-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebpack.prod.js
199 lines (187 loc) · 7.38 KB
/
webpack.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const webpack = require('webpack');
const path = require('path');
const chalk = require('chalk');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const safePostCssParser = require('postcss-safe-parser');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const WebpackMerge = require('webpack-merge');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const commonConfig = require('./webpack.common');
const entryPath = path.join(__dirname, './src');
const outputPath = path.join(__dirname, './dist');
const customizeTheme = require('./src/theme');
const config = {
mode: 'production',
// entry:{
// app: [
// 'whatwg-fetch',
// path.join(entryPath, './index.tsx')
// ]
// },
entry: [
'whatwg-fetch',
path.join(entryPath, './index.tsx')
],
module: {
rules: [
{
oneOf: [
{
test: /\.(css|less)$/,
loader:
[
{
loader: MiniCssExtractPlugin.loader,
},
// {
// loader: require.resolve('style-loader'),
// options: {
// hmr: false,
// },
// },
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
minimize: true,
sourceMap: true,
alias: { '../img': path.join(__dirname, 'public/img') }
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
{
loader: require.resolve('less-loader'),
options: {
sourceMap: true,
javascriptEnabled: true,
modifyVars: customizeTheme
},
},
]
},
]
}
]
},
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin({
cssProcessorOptions: {
parser: safePostCssParser,
map: {
// `inline: false` forces the sourcemap to be output into a
// separate file
inline: false,
// `annotation: true` appends the sourceMappingURL to the end of
// the css file, helping the browser find the sourcemap
annotation: true,
}
},
}),
],
},
plugins: [
new ProgressBarPlugin({
format: ' build [:bar] ' + chalk.green.bold(':percent') + ' (:elapsed seconds)',
clear: false
}),
// new webpack.DefinePlugin({
// "process.env.NODE_ENV": JSON.stringify("production")
// }),
// both development and production
// injected the webpack bundles to `index.html` file.
// @see: https://webpack.js.org/plugins/html-webpack-plugin/
// More config @see: https://github.com/jantimon/html-webpack-plugin#configuration
new HtmlWebpackPlugin({
template: './public/index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
// Minify the code.
new UglifyJsPlugin({
uglifyOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: true,
}),
new webpack.NoEmitOnErrorsPlugin(),
// new ExtractTextPlugin("[name].[hash].css"),
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[name].[hash].css',
}),
new CopyWebpackPlugin(
[
{
from: path.join(__dirname, './public/fonts'),
to: path.join(outputPath, './fonts/'),
// context: 'public'
},
{
from: path.join(__dirname, './public/img'),
to: path.join(outputPath, './img/'),
}
]
),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// Perform type checking and linting in a separate process to speed up compilation
new ForkTsCheckerWebpackPlugin({
async: false,
tsconfig: './tsconfig.json',
tslint: './tslint.json',
}),
]
}
module.exports = WebpackMerge(commonConfig, config);