This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
96 lines (90 loc) · 2.24 KB
/
webpack.config.babel.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
import path from 'path';
import HtmlPlugin from 'html-webpack-plugin';
import WasmPackPlugin from '@wasm-tool/wasm-pack-plugin';
import webpack from 'webpack';
const NODE_MODULES = 'node_modules';
const PATH_DIST = './build';
const PATH_DIST_WASM = './build/wasm';
const PATH_SRC = './src';
const PATH_SRC_WASM = './wasm';
function getPath(filePath) {
return path.resolve(__dirname, filePath);
}
export default () => {
const isDevelopment = process.env.NODE_ENV === 'development';
const filename = isDevelopment ? '[name]' : '[name]-[contenthash:4]';
const exclude = new RegExp(NODE_MODULES);
return {
mode: isDevelopment ? 'development' : 'production',
entry: {
app: getPath(`${PATH_SRC}/index.js`),
},
output: {
filename: `${filename}.js`,
sourceMapFilename: `${filename}.js.map`,
path: getPath(PATH_DIST),
publicPath: '/',
},
resolve: {
modules: [NODE_MODULES],
},
module: {
rules: [
{
test: /\.js$/,
exclude,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jp(e?)g|gif|woff(2?)|svg|ttf|eot)$/,
exclude,
use: [
{
loader: 'file-loader',
options: {
name: `[path]${filename}.[ext]`,
},
},
],
},
],
},
devtool: 'source-map',
devServer: {
clientLogLevel: 'silent',
liveReload: false,
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: new RegExp(NODE_MODULES),
chunks: 'all',
name: 'lib',
},
},
},
},
plugins: [
new HtmlPlugin({
minify: isDevelopment
? false
: {
collapseWhitespace: true,
},
template: getPath(`${PATH_SRC}/index.html`),
}),
new WasmPackPlugin({
crateDirectory: getPath(PATH_SRC_WASM),
outDir: getPath(PATH_DIST_WASM),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
],
};
};