/
webpack.config.js
84 lines (77 loc) 路 1.85 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
import path, { dirname } from 'path'
import { merge } from 'webpack-merge'
import { WebpackManifestPlugin } from 'webpack-manifest-plugin'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const PATHS = {
build: path.join(__dirname, 'build'),
src: path.join(__dirname, 'src'),
node_modules: path.join(__dirname, 'node_modules')
}
const commonConfig = {
entry: {
'app-shell': path.join(PATHS.src, 'client/js/app-shell.js')
},
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
[
'@babel/preset-env',
{
targets: '> 5%, not dead'
}
],
'@babel/preset-react'
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'dynamic-import-node'
]
}
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.json'],
modules: [PATHS.src, 'node_modules'],
symlinks: false
},
output: {
filename: '[name].js',
chunkFilename: '[name].js',
publicPath: '/js/',
path: path.join(PATHS.build, 'public/js')
},
plugins: [new WebpackManifestPlugin()]
}
const productionConfig = {
mode: 'production',
optimization: {
minimize: false
},
output: {
filename: '[chunkhash].[name].js',
chunkFilename: '[chunkhash].[name].js',
publicPath: '/js/',
path: path.join(PATHS.build, 'public/js')
}
}
const developmentConfig = {
mode: 'development'
}
const config = () => {
if (
process.env.NODE_ENV === 'production' ||
process.env.NODE_ENV === 'staging'
) {
return merge(commonConfig, productionConfig)
}
return merge(commonConfig, developmentConfig)
}
export default config