-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.prod.js
169 lines (167 loc) · 5.1 KB
/
webpack.config.prod.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use strict'
const path = require('path')
const webpack = require('webpack')
const publicPath = path.resolve(__dirname, './src/client')
const buildPath = path.resolve(__dirname, './src')
const WebpackAssetsManifest = require('webpack-assets-manifest')
const WebpackMd5Hash = require('webpack-md5-hash')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ExtractLocal = new ExtractTextPlugin({filename: 'stylesheet/stylesLocal.[contenthash].local.css', disable: false, allChunks: true})
const ExtractGlobal = new ExtractTextPlugin({filename: 'stylesheet/stylesGlobal.[contenthash].css', disable: false, allChunks: true})
const CompressionPlugin = require('compression-webpack-plugin')
// const BrotliPlugin = require('brotli-webpack-plugin')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
devtool: 'source-maps',
performance: {
hints: false
},
context: publicPath,
entry: {
bundle: [
'script-loader!jquery/dist/jquery.min.js',
'script-loader!tether/dist/js/tether.min.js',
'script-loader!bootstrap/dist/js/bootstrap.min.js',
'./app.js'
],
vendor: [
'react',
'react-dom',
'react-router'
]
},
output: {
path: path.join(buildPath, 'dist'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
FormComponent: path.resolve(__dirname, 'src/client/scenes/feature/components/FormComponent.jsx'),
Feature: path.resolve(__dirname, 'src/client/scenes/feature/index.jsx'),
TitleComponent: path.resolve(__dirname, 'src/client/scenes/home/components/TitleComponent.jsx'),
Home: path.resolve(__dirname, 'src/client/scenes/home/index.jsx'),
Navigation: path.resolve(__dirname, 'src/client/scenes/shared/navigation/index.jsx'),
Container: path.resolve(__dirname, 'src/client/scenes/Container.js')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules|dist|build/,
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
'react',
['es2015', { 'modules': false }],
'stage-0'
],
plugins: [
'transform-runtime',
[
'babel-plugin-react-css-modules',
{
context: publicPath,
filetypes: {
'.scss': 'postcss-scss'
}
}
]
]
}
},
{
test: /\.local\.(css|scss)$/,
use: ExtractLocal.extract({
fallback: 'style-loader',
use: [
'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
'postcss-loader',
'sass-loader',
{
loader: 'sass-resources-loader',
options: {
resources: [
path.resolve(__dirname, './src/client/styles/scss/variables.scss')
]
}
}
]
})
},
{
test: /^((?!\.local).)+\.(css|scss)$/,
use: ExtractGlobal.extract({
fallback: 'style-loader',
use: [
'css-loader',
'postcss-loader',
'sass-loader'
]
})
},
{
test: /\.(gif|png|jpg)$/,
loader: 'url-loader?limit=25000&name=assets/[name].[hash].[ext]'
}
]
},
plugins: [
// new BundleAnalyzerPlugin(),
/* copy all favicon icons from client/styles/favicon folder to the root of dist folder */
new CopyWebpackPlugin([
{from: 'styles/favicon'}
]),
ExtractLocal,
ExtractGlobal,
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
/* For long term caching. Changing the bundle doesn't change vendor hash */
new WebpackMd5Hash(),
/* Inside manifest.json both localStyles and gloablStyles are generated under same key bundle.css/.map so they overwrite each other. We must change the key name of one of them. */
new WebpackAssetsManifest({
output: 'manifestList.json',
customize: (key, value) => {
if (value.toLowerCase().endsWith('.local.css')) {
return {
key: 'localcss.css',
value: value
}
}
if (value.toLowerCase().endsWith('.local.css.map')) {
return {
key: 'localcss.css.map',
value: value
}
}
}
}),
new CompressionPlugin({
asset: '[file].gz[query]',
algorithm: 'gzip',
test: /\.(js|css|svg|jsx)$/,
threshold: 0,
minRatio: 0.8
})
/* For Brotli compression */
// new BrotliPlugin({
// asset: '[path].br[query]',
// test: /\.(js|css|svg|jsx)$/,
// threshold: 0,
// minRatio: 0.8,
// quality: 10
// })
]
}