1 | const path = require('path');
|
2 |
|
3 | const autoprefixer = require('autoprefixer');
|
4 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
5 | const webpack = require('webpack');
|
6 | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
7 | const merge = require('webpack-merge');
|
8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
9 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
10 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
11 |
|
12 | const base = require('./base');
|
13 |
|
14 | module.exports = arg =>
|
15 | merge(base(arg), {
|
16 | bail: true,
|
17 |
|
18 | mode: 'production',
|
19 |
|
20 | module: {
|
21 | rules: [
|
22 | {
|
23 | test: /\.jsx?$/,
|
24 | include: arg.options.compileNodeModules
|
25 | ? [path.resolve(arg.context, './src'), path.resolve(arg.context, './node_modules')]
|
26 | : path.resolve(arg.context, './src'),
|
27 | loader: 'babel-loader',
|
28 | options: arg.options.noBabelConfig
|
29 | ? {}
|
30 | : {
|
31 | presets: [
|
32 | [
|
33 | '@babel/preset-env',
|
34 | {
|
35 | targets: arg.options.browsers,
|
36 | modules: false,
|
37 | loose: true,
|
38 | useBuiltIns: 'entry',
|
39 | configPath: arg.context,
|
40 | shippedProposals: true,
|
41 | },
|
42 | ],
|
43 | '@babel/preset-react',
|
44 | ],
|
45 | plugins: [
|
46 | ['@babel/plugin-proposal-class-properties', { loose: true }],
|
47 | ['@babel/plugin-proposal-decorators', { legacy: true }],
|
48 | '@babel/plugin-proposal-export-default-from',
|
49 | '@babel/plugin-proposal-export-namespace-from',
|
50 | '@babel/plugin-proposal-optional-chaining',
|
51 | '@babel/plugin-proposal-numeric-separator',
|
52 | '@babel/plugin-proposal-throw-expressions',
|
53 | ],
|
54 | },
|
55 | },
|
56 | {
|
57 | test: /\.css$/,
|
58 | oneOf: [
|
59 | {
|
60 | exclude: /node_modules/,
|
61 | use: [
|
62 | MiniCssExtractPlugin.loader,
|
63 | {
|
64 | loader: 'css-loader',
|
65 | options: { modules: arg.options.cssModules, camelCase: 'only', importLoaders: 1 },
|
66 | },
|
67 | {
|
68 | loader: 'postcss-loader',
|
69 | options: {
|
70 | ident: 'postcss',
|
71 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
72 | },
|
73 | },
|
74 | ],
|
75 | },
|
76 | {
|
77 | include: /node_modules/,
|
78 | use: [
|
79 | MiniCssExtractPlugin.loader,
|
80 | {
|
81 | loader: 'css-loader',
|
82 | options: { importLoaders: 1 },
|
83 | },
|
84 | {
|
85 | loader: 'postcss-loader',
|
86 | options: {
|
87 | ident: 'postcss',
|
88 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
89 | },
|
90 | },
|
91 | ],
|
92 | },
|
93 | ],
|
94 | },
|
95 | {
|
96 | test: /\.less$/,
|
97 | oneOf: [
|
98 | {
|
99 | exclude: /node_modules/,
|
100 | use: [
|
101 | MiniCssExtractPlugin.loader,
|
102 | {
|
103 | loader: 'css-loader',
|
104 | options: { modules: arg.options.cssModules, camelCase: 'only', importLoaders: 1 },
|
105 | },
|
106 | {
|
107 | loader: 'postcss-loader',
|
108 | options: {
|
109 | ident: 'postcss',
|
110 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
111 | },
|
112 | },
|
113 | 'less-loader',
|
114 | ],
|
115 | },
|
116 | {
|
117 | include: /node_modules/,
|
118 | use: [
|
119 | MiniCssExtractPlugin.loader,
|
120 | {
|
121 | loader: 'css-loader',
|
122 | options: { importLoaders: 1 },
|
123 | },
|
124 | {
|
125 | loader: 'postcss-loader',
|
126 | options: {
|
127 | ident: 'postcss',
|
128 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
129 | },
|
130 | },
|
131 | 'less-loader',
|
132 | ],
|
133 | },
|
134 | ],
|
135 | },
|
136 | ],
|
137 | },
|
138 |
|
139 | optimization: {
|
140 | minimizer: [
|
141 | new UglifyJsPlugin({
|
142 | cache: true,
|
143 | parallel: true,
|
144 | sourceMap: true,
|
145 | uglifyOptions: {
|
146 | ie8: arg.options.supportIE8,
|
147 | warnings: true,
|
148 | compress: {
|
149 | warnings: false,
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | comparisons: false,
|
155 | },
|
156 | mangle: {
|
157 | safari10: true,
|
158 | },
|
159 | output: {
|
160 | comments: false,
|
161 |
|
162 |
|
163 | ascii_only: true,
|
164 | },
|
165 | },
|
166 | }),
|
167 | new OptimizeCSSAssetsPlugin({
|
168 | cssProcessorPluginOptions: {
|
169 | preset: ['default', { discardComments: { removeAll: true }, calc: false }],
|
170 | },
|
171 | }),
|
172 | ],
|
173 | },
|
174 |
|
175 | plugins: [
|
176 | new BundleAnalyzerPlugin({
|
177 | analyzerMode: 'static',
|
178 | logLevel: 'warn',
|
179 | reportFilename: 'bundle-report.html',
|
180 | }),
|
181 | new CaseSensitivePathsPlugin(),
|
182 | new MiniCssExtractPlugin(),
|
183 | new webpack.DefinePlugin({
|
184 | __ENV__: JSON.stringify('prod'),
|
185 | }),
|
186 | new webpack.ProgressPlugin(),
|
187 | arg.options.profile && new webpack.debug.ProfilingPlugin(),
|
188 | ].filter(Boolean),
|
189 | });
|