-
Notifications
You must be signed in to change notification settings - Fork 21
/
webpack.config.js
97 lines (95 loc) · 2.42 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
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const buildPath = 'build';
module.exports = {
entry: path.resolve(__dirname, 'src/index.tsx'),
output: {
path: path.resolve(__dirname, buildPath),
filename: 'index.js'
},
module: {
rules: [
{
test: /\.(c|sc|sa)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development'
}
},
'css-loader',
'sass-loader'
]
},
{
test: /\.(js|ts)x?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(png|jpg|gif|woff|svg|ttf)$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public/index.html'),
title: 'TW',
filename: 'index.html'
}),
new MiniCssExtractPlugin({
filename: 'index.css'
}),
new OptimizeCSSAssetsPlugin({
assetNameRegExp: /index\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }]
},
canPrint: true
}),
new UglifyJsPlugin({
sourceMap: false,
uglifyOptions: {
ecma: 8,
compress: {
unused: false
},
output: {
comments: false,
beautify: false
}
}
})
],
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
alias: {
'@api': path.resolve(__dirname, 'src/api/'),
'@components': path.resolve(__dirname, 'src/components/'),
'@config': path.resolve(__dirname, 'src/config/'),
'@pages': path.resolve(__dirname, 'src/pages/'),
'@resource': path.resolve(__dirname, 'src/resource/'),
'@store': path.resolve(__dirname, 'src/store/'),
'@utils': path.resolve(__dirname, 'src/utils/')
}
},
devServer: {
contentBase: path.resolve(__dirname, buildPath),
compress: true,
port: 9000
},
mode: 'development'
};