-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.prod.js
96 lines (93 loc) · 2.53 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path');
module.exports = {
mode: 'production',
entry: {
app: path.resolve(__dirname, 'src/index.tsx')
},
output: {
path: path.resolve(__dirname, 'dist')
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css', '.json'],
},
optimization: {
runtimeChunk: 'single'
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
chunks: ['app'],
minify: {
html5: true,
collapseWhitespace: true,
removeComments: true,
removeEmptyAttributes: true
}
}),
new CleanWebpackPlugin(),
// ensure paths are cased correctly even on windows machines
new CaseSensitivePathsPlugin(),
// create css files for build (different loaders in webpack.dev.js and webpack.prod.js)
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css'
}),
// run ts type checker in a separate process for faster builds
new ForkTsCheckerWebpackPlugin(),
// compression output bundles for file size
new CompressionPlugin()
],
module: {
rules: [
// transpile js and jsx to es5
{
test: [/\.jsx?$/],
exclude: /node_modules/,
resolve: {
extensions: ['.js', 'jsx']
},
use: {
loader: 'babel-loader',
}
},
// transpile ts and tsx to esnext then to es5 with babel
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
},
{
loader: 'ts-loader',
options: {
transpileOnly: true
},
}
],
exclude: /node_modules/,
},
// handle images
{
test: /\.(png|svg|jpg|gif)$/,
// exclude: /(?!node_modules\/@ayx)(node_modules)/,
use: ['file-loader']
},
// handle fonts
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
// exclude: /(?!node_modules\/@ayx)(node_modules)/,
use: ['file-loader']
}
]
},
};