-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
66 lines (62 loc) · 1.61 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
66
import path from 'path';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserWebpackPlugin from 'terser-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import webpack from 'webpack';
const isProduction = process.env.NODE_ENV === 'production';
const config: webpack.Configuration = {
mode: isProduction ? 'production' : 'development',
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.js', '.json', '.css'],
modules: ['src', 'node_modules'],
},
entry: path.resolve(__dirname, 'src'),
module: {
rules: [
{
test: /\.(ts|js)x?$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
],
};
if (isProduction) {
config.optimization = {
minimize: true,
minimizer: [
new TerserWebpackPlugin({
extractComments: false,
}),
new OptimizeCSSAssetsPlugin(),
],
};
} else {
config.devServer = {
port: 8080,
compress: true,
overlay: true,
};
}
export default config;