forked from Fuukei/Sakurairo_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
137 lines (136 loc) · 4.17 KB
/
webpack.common.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 define = require('./define')
const webpack = require('webpack')
const { commitHash } = require('./commit_hash')
/* const { VueLoaderPlugin } = require('vue-loader')
*/const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const package_info = require('./package_info')
const javascript_loader = {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: '3.33',
}
]],
cacheDirectory: true,
cacheCompression: false,
assumptions: {
//https://babeljs.io/docs/en/assumptions
noDocumentAll: true,
noClassCalls: true,
noIncompleteNsImportDetection: true
}
}
}
module.exports = {
entry: {
app: './src/app/',
page: { import: "./src/page/", dependOn: 'app' },
anf: './src/404.ts',
"page-bilibilifav":"./src/page-bilibilifav.ts"
/* lazyload:"lazyload",
smoothscroll:"smoothscroll-for-websites" */
//"customizer":"./src/entries/customizer.js"
},
output: {
filename: '[name].js',
assetModuleFilename: '[hash][ext][query]',
path: define.dist_path,
clean: true, // 在生成文件之前清空 output 目录
},
optimization: {
/* runtimeChunk: {
name: 'runtime',
}, */
splitChunks: {
chunks: 'async',
minSize: 40000,
maxSize: 244000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
//enforceSizeThreshold: 50000,
cacheGroups: {
polyfill: {
test: /[\\/]node_modules[\\/](@babel|core-js|regenerator-runtime)[\\/]/,
name: 'polyfill',
chunks: 'initial',
priority: 60,
enforce: true,
reuseExistingChunk: true
},
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
minChunks: 2,
chunks: "all"
},
default: {
priority: -20,
reuseExistingChunk: true,
},
},
},
},
module: {
rules: [
{
test: /\.ts$/, use: [
javascript_loader,
{
loader: 'ts-loader',
options: {
allowTsInNodeModules: true
}
}]
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: javascript_loader
}, /* {
test: /\.vue$/,
use: [
'vue-loader'
]
}, */ {
test: /\.css$/i,
use: [{ loader: MiniCssExtractPlugin.loader }, "css-loader", 'postcss-loader'],
},
]
},
resolve: {
extensions: ['.js', '.json', '.ts'], // 自动判断后缀名,引入时可以不带后缀
fallback: {
buffer: require.resolve('buffer'),
},
},
plugins: [
/* new VueLoaderPlugin(),
*/ new MiniCssExtractPlugin(),
new webpack.BannerPlugin({
raw: true,
entryOnly: true,
banner: `/*! iro ${commitHash} ${new Date().toLocaleDateString()}*/`,
include: 'app'
}),
new webpack.DefinePlugin({
BUILD_INFO: JSON.stringify({
hash: commitHash,
date: new Date().toLocaleDateString()
}),
PKG_INFO: JSON.stringify(package_info)
})
/* new webpack.DefinePlugin({
'typeof document': JSON.stringify('object'),
'typeof window': JSON.stringify('object'),
DEBUG: undefined
}) */
],
target: "browserslist",
devtool: "source-map",
};