-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack-build-page.config.js
171 lines (160 loc) · 4.11 KB
/
webpack-build-page.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const path = require('path');
const join = path.join;
const resolve = path.resolve;
const os = require('os');
const size = os.cpus().length;
const TerserPlugin = require('terser-webpack-plugin');
const AutoDllPlugin = require('autodll-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const {camelCase} = require('lodash');
// const {TsConfigPathsPlugin} = require('awesome-typescript-loader');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const libraryName = 'rainbow';
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const plugins = [
new VueLoaderPlugin(),
// new TsConfigPathsPlugin({
// configFile: 'tsconfig.json'
// }),
new HtmlWebpackPlugin({
inject: true,
title: libraryName,
favicon: join(__dirname, 'assets/images/logo.png'),
filename: 'index.html',
template: join(__dirname, 'examples-webgl/index.html'),
hash: true,
chunks: ['index'],
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'examples-webgl/live2d'),
to: path.join(__dirname, 'dist/examples-webgl/live2d'),
},
// {
// from: path.join(__dirname, 'assets'),
// to: path.join(__dirname, 'dist/examples-webgl/live2d')
// },
{
from: path.join(__dirname, 'examples-webgl/mock'),
to: path.join(__dirname, 'dist/examples-webgl/mock'),
},
]),
new AutoDllPlugin({
inject: true,
filename: '[name].[contenthash:8].js',
path: './vendor',
entry: {
core: [
// 不能分成多个entry,因为每个entry都可能会依赖同样的库,但同样的库无法通过commonChunks进行合并。
'vue',
'vue-router',
],
},
}),
// new BundleAnalyzerPlugin()
];
module.exports = {
// 也走devDependencies
// mode: 'production',
mode: 'development',
entry: {
index: './examples-webgl/index.ts',
},
// devtool: 'source-map',
output: {
path: join(__dirname, 'dist'),
publicPath: './',
libraryTarget: 'umd',
library: camelCase(libraryName),
filename: `${libraryName}.[contenthash:8].js`,
chunkFilename: `${libraryName}.[contenthash:8].async.js`,
// globalObject: 'this'
},
resolve: {
extensions: ['.js', '.vue', '.json', '.ts'],
alias: {
vue$: 'vue/dist/vue',
'@': path.resolve(__dirname, './examples-webgl'),
src: path.resolve(__dirname, './src'),
'~': path.resolve(__dirname, './'),
},
plugins: [
// new TsConfigPathsPlugin({
// configFile: 'tsconfig.json'
// })
],
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/], // vue 单文件写法
},
},
{
test: /\-worker\.ts$/,
use: [
{
loader: 'worker-loader',
options: {
inline: true,
publicPath: '/src/websocket/',
},
},
],
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
options: {
esModule: false, // 这里设置为false,否则webpack打包img后src为“[object Module]”
name: './images/[name].[ext]',
// limit: 8192
},
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'all',
priority: 1,
minChunks: 2,
reuseExistingChunk: true,
},
},
},
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
parallel: size,
cache: true,
// chunkFilter: chunk => chunk.name !== 'common'
}),
],
},
plugins: plugins,
};