-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
54 lines (51 loc) · 1.3 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
import { Configuration } from 'webpack';
import * as path from 'path';
import * as Htmlplugin from 'html-webpack-plugin';
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as CleanWebpackPlugin from 'clean-webpack-plugin';
import * as OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
const mode = process.env.NODE_ENV as Configuration['mode'];
const isProd = mode === 'production';
const config: Configuration = {
mode,
entry: './src/index.ts',
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'dist')
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
port: 4200,
overlay: true,
stats: 'errors-only',
hot: true
},
stats: {
chunks: false
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.(sa|sc|c)ss$/,
use: [isProd ? MiniCssExtractPlugin.loader : 'style-loader', 'css-loader', 'sass-loader']
}
]
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: [
isProd && new MiniCssExtractPlugin(),
isProd && new OptimizeCssAssetsPlugin(),
new CleanWebpackPlugin(['dist']),
new Htmlplugin({
template: 'src/index.html'
})
].filter(Boolean)
};
export default config;