-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
125 lines (120 loc) · 2.68 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const webpack = require('webpack')
const appDirName = process.cwd()
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
const plugins = [
new HtmlWebpackPlugin({
chunks: ['entry', 'vendor'],
templateParameters: {
title: 'react-template-project',
},
filename: `index.html`,
template: `${appDirName}/public/index.html`,
}),
new MiniCssExtractPlugin({
filename: '[name]/main.[contenthash].css',
chunkFilename: '[name]/[id].[contenthash].css',
ignoreOrder: true,
}),
new CopyWebpackPlugin([
{
from: 'public/*.@(png|svg|jpe?g|gif)',
to: 'assets/',
flatten: true,
},
{
from: 'public/404.html',
flatten: true,
},
]),
]
if (IS_PRODUCTION) {
plugins.unshift(new CleanWebpackPlugin())
}
module.exports = {
mode: IS_PRODUCTION ? 'production' : 'development',
devtool: 'source-map',
entry: {
entry: `${appDirName}/src/index.tsx`,
},
devServer: {
contentBase: `${appDirName}/dist`,
// host: '172.23.62.60',
compress: true,
historyApiFallback: true,
},
output: {
path: `${appDirName}/dist`,
filename: 'entry.[contenthash].js',
chunkFilename: '[name].[contenthash].js',
publicPath: '/',
},
resolve: {
alias: {
'@': appDirName + '/src/',
'@@': appDirName,
},
extensions: ['.wasm', '.mjs', '.js', '.json', '.ts', '.tsx'],
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules\/(react|react-dom|react-router-dom)\//,
name: 'vendor',
chunks: 'all',
},
},
},
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
{
enforce: "pre",
test: /\.js$/,
loader: 'source-map-loader',
},
{
test: /\.(less|css)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'less-loader',
],
},
{
test: /\.(png|svg|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'assets/',
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader',
],
},
],
},
plugins,
}