This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
101 lines (94 loc) · 2.24 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
89
90
91
92
93
94
95
96
97
98
99
100
101
const R = require(`ramda`)
const BundleAnalyzerPlugin = require(`webpack-bundle-analyzer`).BundleAnalyzerPlugin
const CopyPlugin = require(`copy-webpack-plugin`)
const DynamicCdnWebpackPlugin = require(`dynamic-cdn-webpack-plugin`)
const HtmlWebPackPlugin = require(`html-webpack-plugin`)
const SpritePlugin = require(`svg-sprite-loader/plugin`)
const ErrorOverlayPlugin = require(`error-overlay-webpack-plugin`)
const cdnResolvers = require(`./cdn-resolvers`)
const path = require(`path`)
const rootPath = dir => path.resolve(__dirname, dir)
const common = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [`babel-loader`],
},
{
test: /\.(png|jpe?g|gif)$/,
exclude: /node_modules/,
use: [{
loader: `file-loader`,
options: {
name: `[hash].[ext]`,
}
}],
},
{
test: /\.svg$/,
use: [
{
loader: `svg-sprite-loader`,
options: {extract: true}
},
`svgo-loader`,
]
},
]
},
output: {
filename: `bundle.js`,
publicPath: `/`
},
resolve: {
alias: {
root: rootPath(`.`),
common: rootPath(`src/common`),
components: rootPath(`src/components`),
containers: rootPath(`src/containers`),
store: rootPath(`src/store`),
constants: rootPath(`src/constants/`),
}
},
plugins: [
new SpritePlugin(),
new HtmlWebPackPlugin({
template: rootPath(`src/index.html`)
}),
],
}
const develop = {
mode: `development`,
devtool: `cheap-module-source-map`,
devServer: {
historyApiFallback: true,
},
plugins: [
new CopyPlugin([{
from: rootPath(`public`)
}]),
new ErrorOverlayPlugin(),
],
}
const production = {
mode: `production`,
plugins: [
new DynamicCdnWebpackPlugin({
env: `production`,
resolver: cdnResolvers
}),
new BundleAnalyzerPlugin({
analyzerMode: `static`,
reportFilename: rootPath(`bundle-report.html`)
}),
],
}
const makeConfigs = R.mergeDeepWith(R.concat, common)
const config = (
process.env.NODE_ENV === `production`
? makeConfigs(production)
: makeConfigs(develop)
)
module.exports = config