-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
128 lines (124 loc) · 3.72 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
/**
* @type {import('webpack').Configuration}
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const { DefinePlugin } = require('webpack');
config = {
entry: './src/index',
output: {
path: path.join(__dirname, '/build'),
filename: `[name].[contenthash:8].js`
},
target: ["web", "es5"],
resolve: {
alias: {
"@netless/window-manager/dist/style.css": require.resolve("@netless/window-manager").replace("index.js", "style.css"),
"@netless/window-manager": require.resolve("@netless/window-manager"),
"@netless/appliance-plugin/dist/style.css": require.resolve("@netless/appliance-plugin").replace("appliance-plugin.js", "style.css"),
"@netless/appliance-plugin/dist/subWorker.js": require.resolve("@netless/appliance-plugin").replace("appliance-plugin.js", "subWorker.js"),
"@netless/appliance-plugin/dist/fullWorker.js": require.resolve("@netless/appliance-plugin").replace("appliance-plugin.js", "fullWorker.js"),
"@netless/appliance-plugin": require.resolve("@netless/appliance-plugin"),
},
extensions: ['.ts', '.tsx', '.js', "cjs"],
fallback: {
buffer: "buffer",
}
},
optimization: {
minimizer: [new TerserJSPlugin({extractComments: false, parallel: true}), new CssMinimizerPlugin({})],
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
chunks: "all",
cacheGroups: {
white: {
test: /[\\/]node_modules[\\/](white-web-sdk)[\\/]/,
name: 'web-sdk',
chunks: 'all',
priority: 10,
reuseExistingChunk: true
},
video: {
test: /video/,
name: 'video',
chunks: 'all',
priority: 7,
reuseExistingChunk: true
},
netless: {
test: /@netless/,
name: 'netless',
chunks: 'all',
priority: 7,
reuseExistingChunk: true
},
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
priority: 1,
reuseExistingChunk: true
}
}
}
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new MiniCssExtractPlugin()
],
module: {
rules: [
{
test: /\.(ts|js|cjs)x?$/,
resourceQuery: { not: [/raw/] },
use: [
"thread-loader",
'babel-loader',
],
},
{
test: /\.css$/,
use: [{loader: MiniCssExtractPlugin.loader}, 'css-loader']
},
{
test: /\.(svg|png)/,
use: ['file-loader']
},
{
resourceQuery: /raw/,
type: 'asset/source',
}
],
unknownContextCritical: false,
},
cache: {
type: "filesystem",
// 手动修改 node_modules 缓存不会失效。可以通过手动修改 config 或者删除 .cache 文件来触发,同时观察文件名是否有变化。
buildDependencies: {
config: [__filename],
},
}
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.output.filename = '[name].[hash].js';
config.module.rules[0].exclude = /node_modules/;
}
config.plugins.push(new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(argv.mode),
'process.env.DEBUG': argv.mode === "development"
}))
return config;
}