-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.config.js
114 lines (110 loc) · 2.65 KB
/
webpack.production.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
102
103
104
105
106
107
108
109
110
111
112
113
114
/* eslint-disable no-undef */
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CopyPlugin = require('copy-webpack-plugin')
const loaders = require('./webpack.loaders')
const WEBPACK_REPORT = true
module.exports = {
mode: 'production',
entry: ['./src/index.jsx'],
devtool: process.env.WEBPACK_DEVTOOL || 'source-map',
output: {
clean: true,
publicPath: './',
path: path.join(__dirname, 'dist'),
filename: 'js/[contenthash].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
include: /src/,
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
['@babel/preset-react', { runtime: 'automatic' }],
'@babel/preset-typescript',
],
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: false,
},
},
'postcss-loader',
'sass-loader',
],
},
...loaders,
],
},
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
output: {
comments: false,
},
warnings: false,
},
}),
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new MiniCssExtractPlugin({
filename: 'css/[contenthash].css',
}),
new CopyPlugin({
patterns: [
{
from: path.join(__dirname, 'public'),
to: path.join(__dirname, 'dist'),
toType: 'dir',
globOptions: {
ignore: ['**/index.html'],
dot: true,
},
},
],
}),
new HtmlWebpackPlugin({
template: './public/index.html',
inject: 'body',
}),
],
}
if (WEBPACK_REPORT) {
module.exports.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
generateStatsFile: true,
openAnalyzer: false,
reportFilename: path.join(__dirname, 'webpack-report/index.html'),
statsFilename: path.join(__dirname, 'webpack-report/stats.json'),
})
)
}