-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
82 lines (81 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
const path = require('path');
const ESLintPlugin = require('eslint-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = function (env, { mode }) {
return {
mode: mode || 'development',
devtool: 'source-map',
entry: './src/index.tsx',
devServer: {
port: 8080,
historyApiFallback: true,
client: {
overlay: false,
},
},
output: {
publicPath: '/',
filename: path.join('js', `bundle${mode === "production" ? ".[fullhash]" : ""}.js`),
chunkFilename: path.join('js', 'chunks', '[name].[contenthash].js'),
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.less'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['@babel/preset-react', '@babel/preset-typescript'],
},
},
{
test: /\.css$/,
use: [
{
loader: mode !== "production" ? "style-loader" : MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: {
localIdentName: mode === "production" ? "[local]-[hash:base64:5]" : "[path]__[local]--[hash:base64:5]",
},
},
},
],
},
],
},
plugins: [
new ESLintPlugin(),
new HtmlWebpackPlugin({
publicPath: '/',
template: './public/index.html',
favicon: './public/favicon.ico',
minify: mode === 'production' && {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
].concat(mode !== 'production' ? [] : [
new MiniCssExtractPlugin({
filename: path.join("css", `bundle${mode === "production" ? ".[fullhash]" : ""}.css`),
chunkFilename: path.join("css", "chunks", "[name].[contenthash].css"),
}),
]),
};
};