-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (86 loc) · 2.79 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
const path = require('path')
const webpack = require('webpack')
const HTMLPlugin = require('html-webpack-plugin')
module.exports = (env, { mode, PROD = (mode ==='production') }) => ({
context: `${__dirname}/src`,
resolve: {
symlinks: false,
modules: ['src', 'node_modules'],
alias: { res: `${__dirname}/res` },
},
entry: {
app: './app.js',
},
output: {
path: `${__dirname}/dist`,
publicPath: `${process.env.PUBLIC || ''}`,
// chunkhash not working in dev-server
filename: PROD ? '[name]-[chunkhash:8].js' : '[name].js',
},
module: {
rules: [{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules/rui'),
],
use: {
loader: 'babel-loader',
options: {
// ignore babelrc in node_modules
babelrc: false,
presets: [
'@babel/preset-react',
['@babel/preset-env', { modules: false, useBuiltIns: 'usage', corejs: 3, }],
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-class-properties',
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: false }],
'@babel/plugin-proposal-do-expressions',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-partial-application',
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
'babel-plugin-transform-jsxspreadchild',
],
},
},
}, {
test: path.resolve(__dirname, 'res'),
type: 'javascript/auto', // fix json type
loader: 'file-loader',
options: {
name: '[name]-[hash:8].[ext]',
},
}, {
test: /\.val$/,
loader: 'val-loader',
}],
},
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
new webpack.ProvidePlugin({
fetch: ['whatwg-fetch', 'fetch'],
}),
new HTMLPlugin({
template: 'index.html.ejs',
// https://github.com/kangax/html-minifier#options-quick-reference
minify: {
collapseWhitespace: PROD,
removeComments: PROD,
},
}),
// new (require('webpack-bundle-analyzer')).BundleAnalyzerPlugin({ openAnalyzer: false }),
// new (require('webpack-jarvis'))(),
],
})
// default disable comments for `webpack -p`
// https://github.com/webpack-contrib/terser-webpack-plugin/blob/master/src/index.js#L46
Object.defineProperty(require('terser-webpack-plugin').prototype, 'options', {
get() { return this._options },
set(o) { o.terserOptions.output.comments = false; this._options = o },
})