-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
142 lines (128 loc) · 3.48 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const CopyPlugin = require('copy-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
const swSrc = path.join(__dirname, 'src', 'service-worker')
module.exports = {
mode: devMode ? 'development' : 'production',
entry: {
app: path.join(__dirname, 'src', 'index.tsx')
},
target: 'web',
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: '/node_modules/',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true
}
},
{
test: /\.css$/i,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader'
],
},
{
test: /\.less$/,
use: [{
loader: 'style-loader',
}, {
loader: 'css-loader', // translates CSS into CommonJS
}, {
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: { // If you are using less-loader@5 please spread the lessOptions to options directly
// + modifyVars: {
// + 'primary-color': '#1DA57A',
// + 'link-color': '#1DA57A',
// + 'border-radius-base': '2px',
// + },
javascriptEnabled: true,
},
},
}]
},
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' },
},
],
},
output: {
filename: '[name].bundle.js',
publicPath: './',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new AntdDayjsWebpackPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'index.html')
}),
new HtmlWebpackPlugin({
filename: '200.html',
template: path.join(__dirname, 'src', 'index.html')
}),
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css'
}),
new CopyPlugin({
patterns:[
{ from: 'static' }
]
}),
// new ForkTsCheckerWebpackPlugin({
// eslint: {
// files: './src/**/*.{ts,tsx,js,jsx}' // required - same as command `eslint ./src/**/*.{ts,tsx,js,jsx} --ext .ts,.tsx,.js,.jsx`
// }
// }),
new WorkboxWebpackPlugin.InjectManifest({
swSrc,
dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
// Bump up the default maximum size (2mb) that's precached,
// to make lazy-loading failure scenarios less likely.
// See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
})
],
devServer: {
static: {
directory: path.join(__dirname, "./dist")
},
compress: true,
port: 8080,
historyApiFallback: true,
devMiddleware: {
index: true,
mimeTypes: { phtml: 'text/html' },
serverSideRender: true,
writeToDisk: true,
},
},
optimization: {
usedExports: true,
minimizer: [new TerserPlugin({}), new CssMinimizerPlugin({})]
}
};
if (devMode) {
module.exports.devtool = "source-map";
module.exports.module.rules.push({
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
});
}