-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.common.config.js
78 lines (72 loc) · 1.94 KB
/
webpack.common.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
const path = require('path');
const { NoEmitOnErrorsPlugin } = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const TSConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const rules = [{
test: /\.tsx?$/,
exclude: /(node_modules)/,
use: {
loader: 'ts-loader',
options: { transpileOnly: true },
},
}, {
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
}, {
test: /\.(png|jpg|gif|mp3|ico)$/,
use: 'file-loader',
}, {
test: /\.woff(2)?(\?v=\d\.\d\.\d)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
}, {
test: /\.(ttf|eot|svg)(\?v=\d\.\d\.\d)?$/,
loader: 'file-loader',
}];
const optimization = {
noEmitOnErrors: true,
splitChunks: {
cacheGroups: {
// Cache the node_modules
vendors: {
chunks: 'all',
test: /node_modules/,
name: 'vendors',
},
styles: {
// Bundle all of the css into one file
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
},
// Generate a single runtime chunk for better caching
runtimeChunk: 'single',
};
module.exports = {
entry: { app: path.resolve(__dirname, 'src/webapp/index.tsx') },
output: { publicPath: '/' },
module: { rules },
optimization,
plugins: [
new NoEmitOnErrorsPlugin(),
new MiniCssExtractPlugin({ filename: '[name].[hash].css' }),
new HTMLWebpackPlugin({
template: path.resolve(__dirname, 'src/webapp/index.html'),
filename: 'index.html',
inject: 'body',
}),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
navigateFallback: '/index.html',
}),
],
resolve: {
plugins: [new TSConfigPathsPlugin({ configFile: 'tsconfig.json' })],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
};