-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.config.js
99 lines (95 loc) · 2.65 KB
/
webpack.base.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
const path = require('path')
const HtmlPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const fs = require('fs')
const {sources: {RawSource}} = require("webpack");
class CopyPlugin {
// [['src', 'dest'], ['src', 'dest']]
constructor(pairs) {
this.pairs = pairs
}
async readFile(path) {
return new Promise((res, rej) =>
fs.readFile(path, null, (e, d) => e ? rej(e) : res(d)))
}
apply(compiler) {
compiler.hooks.thisCompilation.tap('CopyStaticPlugin', ctx =>
ctx.hooks.processAssets.tap('CopyStaticPlugin', async () => {
for (let [src, dest] of this.pairs) {
ctx.emitAsset(dest, new RawSource(await this.readFile(src)))
}
})
)
}
}
module.exports = {
entry: './src/main.ts',
output: {
filename: "[name].js",
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [{
test: /.ts$/,
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}, {
test: /.vue$/,
loader: 'vue-loader'
}, {
test: /.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /.*/,
include: path.resolve(__dirname, 'asset'),
type: 'asset/resource'
}]
},
resolve: {
extensions: ['.js', '.vue', '.ts'],
alias: {
'@': path.resolve(__dirname, 'src')
}
},
plugins: [
new HtmlPlugin({
template: "./public/index.html", favicon: "./public/favicon.ico"
}),
new VueLoaderPlugin(),
new CopyPlugin([
['public/favicon-16x16.png', 'favicon-16x16.png'],
['public/favicon-32x32.png', 'favicon-32x32.png']])
],
optimization: {
splitChunks: {
chunks: "async",
automaticNameDelimiter: "~",
cacheGroups: {
three: {
chunks: "initial",
test: /node_modules\/three/,
name: 'three',
priority: 20,
enforce: true
},
vendors: {
chunks: "initial",
test: /node_modules/,
name: 'vendor',
priority: 10,
enforce: true
},
default: {
priority: 0,
}
}
}
},
stats: {
modules: false,
chunks: true,
assets: true,
}
}