85 lines
1.8 KiB
JavaScript
85 lines
1.8 KiB
JavaScript
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
// 处理ES模块中的__dirname
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
export default {
|
|
entry: './index.tsx',
|
|
output: {
|
|
filename: 'bundle.js',
|
|
path: path.resolve(__dirname, 'dist'),
|
|
publicPath: '/',
|
|
clean: true,
|
|
},
|
|
mode: 'development',
|
|
devtool: 'eval-cheap-module-source-map',
|
|
devServer: {
|
|
static: {
|
|
directory: __dirname,
|
|
},
|
|
hot: true,
|
|
open: false,
|
|
port: 3000,
|
|
historyApiFallback: true,
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: './index.html',
|
|
favicon: './assets/favicon.ico',
|
|
}),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(ts|tsx)$/,
|
|
exclude: /node_modules/,
|
|
use: [
|
|
{
|
|
loader: 'ts-loader',
|
|
options: {
|
|
transpileOnly: true,
|
|
compilerOptions: {
|
|
noEmit: false,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.(js|jsx)$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: [
|
|
['@babel/preset-env', { targets: 'defaults' }],
|
|
'@babel/preset-react',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
test: /\.(scss|sass)$/,
|
|
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
use: ['style-loader', 'css-loader'],
|
|
},
|
|
{
|
|
test: /\.(png|svg|jpg|jpeg|gif)$/i,
|
|
type: 'asset/resource',
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, 'src'),
|
|
},
|
|
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
},
|
|
};
|