-
Notifications
You must be signed in to change notification settings - Fork 115
/
webpack.config.prod.js
136 lines (120 loc) · 3.61 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
import config from 'config';
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import SaveAssetsJson from 'assets-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import precss from 'precss';
import postcssCssnext from 'postcss-cssnext';
import webpackConfig, { JS_SOURCE } from './webpack.config.common';
// ----------------------------------------------------------
// CONSTANT DECLARATION
// ----------------------------------------------------------
const PUBLIC_PATH = config.get('publicPath');
const APP_ENTRY_POINT = `${JS_SOURCE}/router`;
const webpackProdOutput = {
publicPath: PUBLIC_PATH,
filename: 'assets/[name]-[hash].js',
chunkFilename: "assets/[id].[hash].js",
};
// This section is for common chunk behavior
// do we need to exclude css from this rule
const optimizationMinChunks = config.get('optimization.cssExclusion') ?
function(module, count) {
return module.resource &&
!(/\.css/).test(module.resource) &&
count >= config.get('optimization.commonMinCount');
}
:
config.get('optimization.commonMinCount');
const html = config.get('html');
// Please configure this section if you plan
// to deploy the generated html to production.
// I don't mind you name your page as Retro
// if you want to ...
const htmlPlugins = html.map((page) =>
new HtmlWebpackPlugin({
title: page.title,
template: `src/assets/template/${page.template}`,
inject: 'body',
filename: page.filename,
minify: {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
}
})
);
// ----------------------------------------------------------
// Extending Webpack Configuration
// ----------------------------------------------------------
// Merges webpackProdOutput and webpackConfig.output
webpackConfig.output = Object.assign(webpackConfig.output, webpackProdOutput);
webpackConfig.module.rules = webpackConfig.module.rules.concat({
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: 'css-loader',
options: { sourceMap: true, importLoaders: 1 }
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: () => [
precss(),
postcssCssnext({
browsers: ['last 2 versions', 'ie >= 9'],
compress: true,
}),
],
},
}
]
})
});
webpackConfig.devtool = 'source-map';
webpackConfig.entry = {
app: ['babel-polyfill', path.resolve(__dirname, APP_ENTRY_POINT)],
};
webpackConfig.output.publicPath = '/';
webpackConfig.plugins.push(
new webpack.DefinePlugin({
__CONFIG__: JSON.stringify(config.get('app')),
'process.env': {
NODE_ENV: JSON.stringify('production')
},
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
// how you want your code to be optimized
// all configurable
new webpack.IgnorePlugin(/un~$/),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'assets/common-[hash].js',
minChunks: optimizationMinChunks,
}),
new SaveAssetsJson({
path: path.join(__dirname, 'docroot'),
filename: 'assets.json',
prettyPrint: true,
metadata: {
version: process.env.PACKAGE_VERSION,
},
}),
new ExtractTextPlugin({
filename: 'assets/[name]-[hash].css',
disable: false,
allChunks: true,
})
);
webpackConfig.plugins = webpackConfig.plugins.concat(htmlPlugins);
export default webpackConfig;