This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
webpack.config.js
executable file
·137 lines (132 loc) · 3.08 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
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const os = require('os');
const cpuLength = os.cpus().length;
module.exports = {
devtool: 'cheap-module-source-map',
entry: path.resolve(__dirname, './renderer/index.tsx'),
mode: 'development',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build'),
publicPath: '/',
},
resolve: {
alias: {
// dir
src: path.resolve(__dirname, 'renderer'),
},
extensions: ['.tsx', '.ts', '.js', '.jsx'],
},
module: {
noParse:[/jquery/],
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['ts-loader']
},
{
test: /(\.js?|\.jsx?)$/,
exclude: /(node_modules|bower_components)/,
use: ["babel-loader?cacheDirectory"]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
},
},
{
test: /\.(ico|woff|eot|ttf|woff2|icns)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 500, // 小于500B的文件直接写入bunndle
name: '[name]_[hash:8].[ext]',
outputPath: 'resources/assets',
},
},
]
},
{
test: /\.(png|jpg|gif|svg|jpeg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'resources/images',
},
}
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
},
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new ESLintPlugin({
extensions: ['.ts', '.tsx'],
context: path.resolve(__dirname, './'),
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './renderer/index.html',
inject: 'body',
minify: true
}),
],
optimization: {
splitChunks: {
chunks: 'all',
minSize: 20000,
minRemainingSize: 0,
minChunks: 2,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
name: 'vendors_[hash:8].[ext]',
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
name: 'bundle_[hash:8].[ext]',
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
}
},
devServer: {
host: 'localhost',
port: 3001,
compress: true,
contentBase: '.',
historyApiFallback: true,
hot: true,
inline: true,
liveReload: false
},
target: 'electron-renderer'
};