-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
149 lines (149 loc) · 3.86 KB
/
webpack.config.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserJSPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
const webpack = require('webpack');
const apiMocker = require("mocker-api");
//html-minifier-terser
module.exports = {
mode: 'development',
entry: {
app: "./src/index.tsx",
// "editor.worker": "monaco-editor/esm/vs/editor/editor.worker.js",
// "json.worker": "monaco-editor/esm/vs/language/json/json.worker",
// "css.worker": "monaco-editor/esm/vs/language/css/css.worker",
// "html.worker": "monaco-editor/esm/vs/language/html/html.worker",
// "ts.worker": "monaco-editor/esm/vs/language/typescript/ts.worker"
},
module: {
rules: [
{
test: /froala-editor/,
parser: {
amd: false,
}
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
// {
// loader: "style-loader",
// options: { injectType: "singletonStyleTag" }
// },
MiniCssExtractPlugin.loader,
"css-loader",
// 'postcss-loader',
]
},
{
test: /\.styl$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"stylus-loader",
]
},
{
test: /\.(png|svg|jpg|gif|woff|woff2?|eot|ttf|otf)\??.*$/,
use: ["url-loader"]
// use: ["file-loader"]
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
devtool: "source-map",//inline-source-map
devServer: {
contentBase: "./dist",
historyApiFallback: {
rewrites: [{ from: /^\/(login|admin.*)$/, to: "/index.html" }]
},
before(app) {
apiMocker(app, path.resolve("./mock/index.js"));
},
proxy: {
// '/api': 'http://localhost:3000'
}
},
watchOptions: {
ignored: /node_modules/,
},
optimization: {
splitChunks: {
// include all types of chunks
chunks: 'all',
cacheGroups: {
vendor: {
name: "vendor",
test: /[\\/]node_modules[\\/]/,
chunks: "all",
priority: 32 // 优先级
},
common: {
name: "common",
test: /[\\/]src[\\/]components/,
minSize: 1024,
chunks: "all",
priority: 16
}
}
},
usedExports: true,
minimizer: [
new TerserJSPlugin({}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessorOptions: {
safe: true,
autoprefixer: { disable: true }, //忽略autoprefixer
mergeLonghand: false,
discardComments: {
removeAll: true // 移除注释
}
},
canPrint: true
})
],
},
resolve:{
extensions: [".tsx", ".ts", ".js"],
alias:{
'@': path.resolve(__dirname, './src')
},
},
// externals: {
// 'react': "React",
// 'react-dom': "ReactDOM",
// },
plugins: [
new HtmlWebpackPlugin({
title: "AdminUI",
template: "./src/index.html",
chunks: ['app']
}),
new CleanWebpackPlugin(),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new MiniCssExtractPlugin({
filename: 'css/[name]-[chunkhash:6].css',
ignoreOrder: true
}),
// new MonacoWebpackPlugin({
// languages: ["typescript","javascript", "css", "html", "json"],
// features: ["coreCommands", "find"]
// })
],
output: {
publicPath: '/',
filename: "js/[name]-[chunkhash:6].js",
path: path.resolve(__dirname, "dist"),
}
};