-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
101 lines (95 loc) · 2.15 KB
/
webpack.config.js
File metadata and controls
101 lines (95 loc) · 2.15 KB
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
import Path from 'path';
import { DefinePlugin, NormalModuleReplacementPlugin } from 'webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import escapeRegExp from './src/lib/helpers/escapeRegExp';
import pkg from './package.json';
// eslint-disable-next-line no-process-env
const { NODE_ENV } = process.env;
function production(value = true) {
return NODE_ENV === 'production' && value;
}
export default {
devtool: `${production('hidden') || 'inline'}-source-map`,
entry: Path.resolve('src/client'),
output: {
path: Path.resolve('dist'),
filename: 'client.browser.js',
library: 'ImportClient',
libraryExport: 'default'
},
mode: production(NODE_ENV) || 'development',
resolve: {
alias: {
url$: Path.resolve('src/client/shims/url'),
vm$: Path.resolve('src/client/shims/vm')
}
},
plugins: [
new DefinePlugin({
'process.browser': true
}),
new NormalModuleReplacementPlugin(
new RegExp(escapeRegExp(Path.resolve('package.json'))),
Path.resolve('src/client/shims/_package.json')
),
production(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
defaultSizes: 'parsed',
reportFilename: '.report.html',
openAnalyzer: false
})
)
].filter(Boolean),
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: true,
presets: [
[
'@babel/env',
{
exclude: [
// use fast-async instead
'transform-async-to-generator',
'transform-regenerator'
],
modules: false,
targets: {
browsers: ['> 0.25%', 'not dead']
},
useBuiltIns: 'usage'
}
]
],
plugins: [['module:fast-async', { spec: true }]]
}
}
},
{
test: Path.resolve('package.json'),
use: {
loader: 'string-replace-loader',
options: {
multiple: [
{
search: 'WEBPACK_STRING_REPLACE_PKG_NAME',
replace: pkg.name
},
{
search: 'WEBPACK_STRING_REPLACE_PKG_VERSION',
replace: pkg.version
}
],
strict: true
}
}
}
]
}
};