-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.babel.js
125 lines (120 loc) · 2.56 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
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
import path from 'path'
import merge from 'webpack-merge'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import CircularDependencyPlugin from 'circular-dependency-plugin'
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
const target = process.env.npm_lifecycle_event
const common = {
entry: [`@babel/polyfill`, path.join(process.cwd(), `src/index.jsx`)],
output: {
path: path.resolve(process.cwd(), `build/public`),
publicPath: `/`
},
module: {
rules: [
{
test: /\.js|x$/,
exclude: /node_modules/,
use: {loader: `babel-loader`}
},
{
test: /\.(png|jpe?g|gif|woff2?|ttf|eot)$/,
loader: `url-loader`,
},
{
test: /\.css$/,
use: [
{loader: MiniCssExtractPlugin.loader},
`css-loader`]
},
{
type: `javascript/auto`,
test: /manifest\.json/,
use: [{
loader: `file-loader`,
options: {
name: `./[name].[ext]`
}
}]
},
]
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
filename: `../index.html`,
template: `src/index.html`,
chunks: [`main`]
}),
],
resolve: {
modules: [`src`, `node_modules`],
extensions: [`.js`, `.jsx`],
mainFields: [
`browser`,
`jsnext:main`,
`main`
],
alias: {moment: `moment/moment.js`}
},
target: `web`,
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: `initial`,
name: `vendor`,
},
},
},
},
}
let result = {}
switch (target) {
case `webpack:analize`:
common.plugins.push(new BundleAnalyzerPlugin())
case `build`:
result = merge(common, {
output: {
filename: `[name].[chunkhash].js`,
chunkFilename: `[name].[chunkhash].chunk.js`
},
mode: `production`,
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: `[name].[chunkhash].css`,
chunkFilename: `[name].[chunkhash].chunk.css`,
}),
],
})
break
case `webpack:watch`:
result = merge(common, {
output: {
filename: `[name].js`,
chunkFilename: `[name].chunk.js`,
crossOriginLoading: `anonymous`
},
mode: `development`,
plugins: [
new CircularDependencyPlugin({
exclude: /a\.js|node_modules/,
failOnError: false
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: `[name].css`,
chunkFilename: `[name].chunk.css`,
}),
],
})
break
default:
result = common
}
export default result