-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
65 lines (64 loc) · 2 KB
/
webpack.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
module.exports = (env, argv) => ({
devtool: argv.mode === 'production' ? 'source-map' : 'inline-source-map',
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
transpileOnly: true,
},
},
{
test: /\.(s*)css$/,
use: [
argv.mode === 'production'
? MiniCssExtractPlugin.loader
: 'style-loader',
'css-loader',
'sass-loader',
],
},
],
},
optimization: {
minimizer:
argv.mode === 'production'
? [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})]
: [],
},
plugins: [
new CleanWebpackPlugin({}),
new ForkTsCheckerWebpackPlugin({
async: true,
useTypescriptIncrementalApi: true,
measureCompilationTime: true,
memoryLimit: 4096,
}),
new ForkTsCheckerNotifierWebpackPlugin({ excludeWarnings: true }),
new HtmlWebpackPlugin({
inject: 'body',
template: path.resolve(__dirname, './src/templates/index.html'),
title: 'TS React Boilerplate',
}),
new MiniCssExtractPlugin({
filename: argv.mode === 'production' ? '[name].[hash].css' : '[name].css',
chunkFilename:
argv.mode === 'production' ? '[id].[hash].css' : '[id].css',
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
});