-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.base.js
83 lines (80 loc) · 1.91 KB
/
webpack.base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//@ts-check
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: path.join(__dirname, './src/view/index.tsx'), // 入口文件
output: {
filename: 'static/js/[name].js',
path: path.join(__dirname, './out/dist'),
clean: true,
publicPath: '/',
},
module: {
rules: [
{
test: /.(ts|tsx)$/, // 匹配.ts, tsx文件
exclude: [
/node_modules/,
path.resolve(__dirname, './src/bard/')
],
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-react',
'@babel/preset-typescript'
]
}
}
},
{
test: /\.less$/i,
use: [
// compiles Less to CSS
"style-loader",
{
loader: 'css-loader',
options: {
modules: {
auto: /\.module\.less$/,
localIdentName: '[name]__[local]-[hash:base64:5]',
},
},
},
"less-loader",
],
},
{
test: /\.css$/i,
use: [
"style-loader",
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name]__[local]--[hash:base64:5]',
},
},
},
"postcss-loader"
],
},
],
},
resolve: {
extensions: ['.js', '.tsx', '.ts'],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/view/index.html'),
inject: true, // 自动注入静态资源
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
chunkFilename: '[name].[contenthash:8].chunk.css',
ignoreOrder: true,
}),
],
};