-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
65 lines (63 loc) · 1.56 KB
/
webpack.config.ts
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
import { resolve } from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin'; // eslint-disable-line import/default -- WTF
import { GenerateSW } from 'workbox-webpack-plugin';
import type { Configuration } from 'webpack';
const NODE_ENV =
process.env.NODE_ENV === 'production' ? 'production' : 'development';
const distPath = resolve(__dirname, 'dist');
const config: Configuration = {
mode: NODE_ENV,
entry: resolve(__dirname, 'src', 'index.tsx'),
output: {
path: distPath,
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader'
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
svgo: {
plugins: [{ removeViewBox: false }]
}
}
}
]
},
{
test: /\.ya?ml$/,
type: 'json',
use: 'yaml-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
plugins: [
new HtmlWebpackPlugin({
template: resolve(__dirname, 'src', 'index.html')
}),
new CopyPlugin({ patterns: ['resources'] }),
...(NODE_ENV === 'production'
? [
new GenerateSW({
swDest: resolve(distPath, 'sw.js'),
skipWaiting: true,
clientsClaim: true,
cleanupOutdatedCaches: true
})
]
: [])
],
devtool: NODE_ENV === 'development' ? 'inline-source-map' : void 0
};
export default config;