-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
106 lines (104 loc) · 3.14 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const curHash = '[hash]';
module.exports = {
context: path.resolve(__dirname, 'static'),
mode: 'development',
entry: {
app: './js/app.js',
},
devServer: {
host: '0.0.0.0',
port: 3000,
historyApiFallback: true,
disableHostCheck: true,
},
output: {
filename: `[name].${curHash}.js`,
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /\/static/,
terserOptions: {
mangle: true,
compress: false,
output: {
comments: false,
},
},
extractComments: false,
}),
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json', '.scss', '.css'],
alias: {
'@': path.resolve(__dirname, 'static'),
'@models': path.resolve(__dirname, 'static/js/models'),
'@components': path.resolve(__dirname, 'static/js/components'),
'@views': path.resolve(__dirname, 'static/js/views'),
'@controllers': path.resolve(__dirname, 'static/js/controllers'),
'@libs': path.resolve(__dirname, 'static/js/libs'),
'@css': path.resolve(__dirname, 'static/css'),
},
},
plugins: [
new HTMLWebpackPlugin({
template: './index.html',
filename: 'index.html',
minify: {
collapseWhitespace: true,
},
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].[hash].css',
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'static/sw.js'),
}),
],
module: {
rules: [{
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
}, {
loader: 'postcss-loader',
options: {
config: {
path: 'postcss.config.js',
},
},
}],
}, {
test: /\.xml$/,
use: [{
loader: 'fest-webpack-loader',
}],
}, {
test: /\.(png|svg|jpe?g|gif)$/,
use: [{
loader: 'file-loader',
}],
}, {
test: /\.(j|t)s$/,
exclude: /node_modules/,
loader: ['babel-loader', 'ts-loader'],
}],
},
};