@umijs/bundler-webpack 4.0.0-rc.14 → 4.0.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.js +48 -59
- package/dist/cli.js +6 -15
- package/dist/client/client.js +34 -47
- package/dist/config/_sampleFeature.js +6 -17
- package/dist/config/assetRules.js +44 -55
- package/dist/config/bundleAnalyzerPlugin.js +12 -23
- package/dist/config/compressPlugin.js +68 -76
- package/dist/config/config.js +177 -185
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +93 -83
- package/dist/config/definePlugin.js +11 -19
- package/dist/config/detectDeadCodePlugin.js +16 -21
- package/dist/config/fastRefreshPlugin.js +11 -22
- package/dist/config/forkTSCheckerPlugin.js +11 -22
- package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
- package/dist/config/ignorePlugin.js +10 -21
- package/dist/config/javaScriptRules.js +151 -162
- package/dist/config/manifestPlugin.js +10 -18
- package/dist/config/miniCSSExtractPlugin.js +12 -23
- package/dist/config/nodePolyfill.js +14 -21
- package/dist/config/nodePrefixPlugin.js +8 -19
- package/dist/config/progressPlugin.js +7 -18
- package/dist/config/purgecssWebpackPlugin.js +15 -26
- package/dist/config/speedMeasureWebpackPlugin.js +12 -23
- package/dist/config/svgRules.js +43 -47
- package/dist/dev.js +101 -112
- package/dist/loader/svgr.js +4 -13
- package/dist/loader/swc.js +9 -14
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
- package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
- package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
- package/dist/schema.js +18 -6
- package/dist/server/server.d.ts +1 -1
- package/dist/server/server.js +161 -170
- package/dist/server/ws.d.ts +1 -1
- package/dist/types.d.ts +2 -6
- package/package.json +9 -11
- package/dist/server/https.d.ts +0 -4
- package/dist/server/https.js +0 -74
package/dist/build.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -17,58 +8,56 @@ const utils_1 = require("@umijs/utils");
|
|
|
17
8
|
const webpack_1 = __importDefault(require("../compiled/webpack"));
|
|
18
9
|
const config_1 = require("./config/config");
|
|
19
10
|
const types_1 = require("./types");
|
|
20
|
-
function build(opts) {
|
|
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
|
-
if (err
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
reject(err);
|
|
60
|
-
}
|
|
61
|
-
if (stats) {
|
|
62
|
-
const errorMsg = stats.toString('errors-only');
|
|
63
|
-
// console.error(errorMsg);
|
|
64
|
-
reject(new Error(errorMsg));
|
|
65
|
-
}
|
|
11
|
+
async function build(opts) {
|
|
12
|
+
const webpackConfig = await (0, config_1.getConfig)({
|
|
13
|
+
cwd: opts.cwd,
|
|
14
|
+
rootDir: opts.rootDir,
|
|
15
|
+
env: types_1.Env.production,
|
|
16
|
+
entry: opts.entry,
|
|
17
|
+
userConfig: opts.config,
|
|
18
|
+
analyze: process.env.ANALYZE,
|
|
19
|
+
babelPreset: opts.babelPreset,
|
|
20
|
+
extraBabelPlugins: [
|
|
21
|
+
...(opts.beforeBabelPlugins || []),
|
|
22
|
+
...(opts.extraBabelPlugins || []),
|
|
23
|
+
],
|
|
24
|
+
extraBabelPresets: [
|
|
25
|
+
...(opts.beforeBabelPresets || []),
|
|
26
|
+
...(opts.extraBabelPresets || []),
|
|
27
|
+
],
|
|
28
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
29
|
+
chainWebpack: opts.chainWebpack,
|
|
30
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
31
|
+
cache: opts.cache,
|
|
32
|
+
});
|
|
33
|
+
let isFirstCompile = true;
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
utils_1.rimraf.sync(webpackConfig.output.path);
|
|
36
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
37
|
+
compiler.run((err, stats) => {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = opts.onBuildComplete) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
40
|
+
err,
|
|
41
|
+
stats,
|
|
42
|
+
isFirstCompile,
|
|
43
|
+
time: stats ? stats.endTime - stats.startTime : null,
|
|
44
|
+
});
|
|
45
|
+
isFirstCompile = false;
|
|
46
|
+
if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
|
|
47
|
+
if (err) {
|
|
48
|
+
// console.error(err);
|
|
49
|
+
reject(err);
|
|
66
50
|
}
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
if (stats) {
|
|
52
|
+
const errorMsg = stats.toString('errors-only');
|
|
53
|
+
// console.error(errorMsg);
|
|
54
|
+
reject(new Error(errorMsg));
|
|
69
55
|
}
|
|
70
|
-
|
|
71
|
-
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
resolve(stats);
|
|
59
|
+
}
|
|
60
|
+
compiler.close(() => { });
|
|
72
61
|
});
|
|
73
62
|
});
|
|
74
63
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -40,11 +31,11 @@ if ((0, fs_1.existsSync)(configFile)) {
|
|
|
40
31
|
}
|
|
41
32
|
Object.assign(config, args);
|
|
42
33
|
if (command === 'build') {
|
|
43
|
-
(() =>
|
|
34
|
+
(async () => {
|
|
44
35
|
process.env.NODE_ENV = 'production';
|
|
45
36
|
(0, assert_1.default)(entry, `Build failed: entry not found.`);
|
|
46
37
|
try {
|
|
47
|
-
|
|
38
|
+
await (0, build_1.build)({
|
|
48
39
|
config,
|
|
49
40
|
cwd,
|
|
50
41
|
entry: {
|
|
@@ -55,14 +46,14 @@ if (command === 'build') {
|
|
|
55
46
|
catch (e) {
|
|
56
47
|
console.error(e);
|
|
57
48
|
}
|
|
58
|
-
})
|
|
49
|
+
})();
|
|
59
50
|
}
|
|
60
51
|
else if (command === 'dev') {
|
|
61
|
-
(() =>
|
|
52
|
+
(async () => {
|
|
62
53
|
process.env.NODE_ENV = 'development';
|
|
63
54
|
try {
|
|
64
55
|
(0, assert_1.default)(entry, `Build failed: entry not found.`);
|
|
65
|
-
|
|
56
|
+
await (0, dev_1.dev)({
|
|
66
57
|
config,
|
|
67
58
|
cwd,
|
|
68
59
|
port: process.env.PORT,
|
|
@@ -77,7 +68,7 @@ else if (command === 'dev') {
|
|
|
77
68
|
catch (e) {
|
|
78
69
|
console.error(e);
|
|
79
70
|
}
|
|
80
|
-
})
|
|
71
|
+
})();
|
|
81
72
|
}
|
|
82
73
|
else {
|
|
83
74
|
error(`Unsupported command ${command}.`);
|
package/dist/client/client.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -64,7 +55,7 @@ let hasCompileErrors = false;
|
|
|
64
55
|
let hadRuntimeError = false;
|
|
65
56
|
const pingUrl = getPingUrl();
|
|
66
57
|
const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
|
|
67
|
-
socket.addEventListener('message', ({ data }) =>
|
|
58
|
+
socket.addEventListener('message', async ({ data }) => {
|
|
68
59
|
data = JSON.parse(data);
|
|
69
60
|
if (data.type === 'connected') {
|
|
70
61
|
console.log(`[webpack] connected.`);
|
|
@@ -75,28 +66,26 @@ socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void
|
|
|
75
66
|
else {
|
|
76
67
|
handleMessage(data).catch(console.error);
|
|
77
68
|
}
|
|
78
|
-
})
|
|
79
|
-
function waitForSuccessfulPing(ms = 1000) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
89
|
-
}
|
|
69
|
+
});
|
|
70
|
+
async function waitForSuccessfulPing(ms = 1000) {
|
|
71
|
+
// eslint-disable-next-line no-constant-condition
|
|
72
|
+
while (true) {
|
|
73
|
+
try {
|
|
74
|
+
await fetch(pingUrl);
|
|
75
|
+
break;
|
|
90
76
|
}
|
|
91
|
-
|
|
77
|
+
catch (e) {
|
|
78
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
92
81
|
}
|
|
93
|
-
socket.addEventListener('close', () =>
|
|
82
|
+
socket.addEventListener('close', async () => {
|
|
94
83
|
if (pingTimer)
|
|
95
84
|
clearInterval(pingTimer);
|
|
96
85
|
console.info('[webpack] Dev server disconnected. Polling for restart...');
|
|
97
|
-
|
|
86
|
+
await waitForSuccessfulPing();
|
|
98
87
|
location.reload();
|
|
99
|
-
})
|
|
88
|
+
});
|
|
100
89
|
ErrorOverlay.startReportingRuntimeErrors({
|
|
101
90
|
onError: function () {
|
|
102
91
|
hadRuntimeError = true;
|
|
@@ -234,25 +223,23 @@ function tryApplyUpdates(onHotUpdateSuccess) {
|
|
|
234
223
|
handleApplyUpdates(err, null);
|
|
235
224
|
});
|
|
236
225
|
}
|
|
237
|
-
function handleMessage(payload) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
});
|
|
226
|
+
async function handleMessage(payload) {
|
|
227
|
+
// console.log('[payload]', payload);
|
|
228
|
+
switch (payload.type) {
|
|
229
|
+
case constants_1.MESSAGE_TYPE.hash:
|
|
230
|
+
handleAvailableHash(payload.data);
|
|
231
|
+
break;
|
|
232
|
+
case constants_1.MESSAGE_TYPE.stillOk:
|
|
233
|
+
case constants_1.MESSAGE_TYPE.ok:
|
|
234
|
+
handleSuccess();
|
|
235
|
+
break;
|
|
236
|
+
case constants_1.MESSAGE_TYPE.errors:
|
|
237
|
+
handleErrors(payload.data);
|
|
238
|
+
break;
|
|
239
|
+
case constants_1.MESSAGE_TYPE.warnings:
|
|
240
|
+
handleWarnings(payload.data);
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
// Do nothing
|
|
244
|
+
}
|
|
258
245
|
}
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.addSampleFeature = void 0;
|
|
13
|
-
function addSampleFeature(opts) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
env;
|
|
20
|
-
});
|
|
4
|
+
async function addSampleFeature(opts) {
|
|
5
|
+
const { config, userConfig, cwd, env } = opts;
|
|
6
|
+
config;
|
|
7
|
+
userConfig;
|
|
8
|
+
cwd;
|
|
9
|
+
env;
|
|
21
10
|
}
|
|
22
11
|
exports.addSampleFeature = addSampleFeature;
|
|
@@ -1,61 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.addAssetRules = void 0;
|
|
13
|
-
function addAssetRules(opts) {
|
|
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
|
-
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
58
|
-
});
|
|
4
|
+
async function addAssetRules(opts) {
|
|
5
|
+
const { config, userConfig } = opts;
|
|
6
|
+
const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
|
|
7
|
+
const rule = config.module.rule('asset');
|
|
8
|
+
rule
|
|
9
|
+
.oneOf('avif')
|
|
10
|
+
.test(/\.avif$/)
|
|
11
|
+
.type('asset')
|
|
12
|
+
.mimetype('image/avif')
|
|
13
|
+
.parser({
|
|
14
|
+
dataUrlCondition: {
|
|
15
|
+
maxSize: inlineLimit,
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
.generator({
|
|
19
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
20
|
+
});
|
|
21
|
+
rule
|
|
22
|
+
.oneOf('image')
|
|
23
|
+
.test(/\.(bmp|gif|jpg|jpeg|png)$/)
|
|
24
|
+
.type('asset')
|
|
25
|
+
.parser({
|
|
26
|
+
dataUrlCondition: {
|
|
27
|
+
maxSize: inlineLimit,
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
.generator({
|
|
31
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
32
|
+
});
|
|
33
|
+
const fallback = rule
|
|
34
|
+
.oneOf('fallback')
|
|
35
|
+
.exclude.add(/^$/) /* handle data: resources */
|
|
36
|
+
.add(/\.(js|mjs|jsx|ts|tsx)$/)
|
|
37
|
+
.add(/\.(css|less|sass|scss|stylus)$/)
|
|
38
|
+
.add(/\.html$/)
|
|
39
|
+
.add(/\.json$/);
|
|
40
|
+
if (userConfig.mdx) {
|
|
41
|
+
fallback.add(/\.mdx?$/);
|
|
42
|
+
}
|
|
43
|
+
fallback
|
|
44
|
+
.end()
|
|
45
|
+
.type('asset/resource')
|
|
46
|
+
.generator({
|
|
47
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
59
48
|
});
|
|
60
49
|
}
|
|
61
50
|
exports.addAssetRules = addAssetRules;
|
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.addBundleAnalyzerPlugin = void 0;
|
|
13
4
|
// @ts-ignore
|
|
14
5
|
const webpack_bundle_analyzer_1 = require("@umijs/bundler-webpack/compiled/webpack-bundle-analyzer");
|
|
15
|
-
function addBundleAnalyzerPlugin(opts) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]);
|
|
28
|
-
});
|
|
6
|
+
async function addBundleAnalyzerPlugin(opts) {
|
|
7
|
+
const { config } = opts;
|
|
8
|
+
config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
|
|
9
|
+
// https://github.com/webpack-contrib/webpack-bundle-analyzer
|
|
10
|
+
{
|
|
11
|
+
analyzerMode: 'server',
|
|
12
|
+
analyzerPort: process.env.ANALYZE_PORT || 8888,
|
|
13
|
+
openAnalyzer: false,
|
|
14
|
+
logLevel: 'info',
|
|
15
|
+
defaultSizes: 'parsed',
|
|
16
|
+
},
|
|
17
|
+
]);
|
|
29
18
|
}
|
|
30
19
|
exports.addBundleAnalyzerPlugin = addBundleAnalyzerPlugin;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -20,72 +11,73 @@ const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSM
|
|
|
20
11
|
const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
|
|
21
12
|
const types_1 = require("../types");
|
|
22
13
|
const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
|
|
23
|
-
function addCompressPlugin(opts) {
|
|
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
|
-
terserOptions
|
|
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
|
-
|
|
14
|
+
async function addCompressPlugin(opts) {
|
|
15
|
+
const { config, userConfig, env } = opts;
|
|
16
|
+
const jsMinifier = userConfig.jsMinifier || types_1.JSMinifier.esbuild;
|
|
17
|
+
const cssMinifier = userConfig.cssMinifier || types_1.CSSMinifier.esbuild;
|
|
18
|
+
if (env === types_1.Env.development ||
|
|
19
|
+
process.env.COMPRESS === 'none' ||
|
|
20
|
+
(jsMinifier === types_1.JSMinifier.none && cssMinifier === types_1.CSSMinifier.none)) {
|
|
21
|
+
config.optimization.minimize(false);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
config.optimization.minimize(true);
|
|
25
|
+
let minify;
|
|
26
|
+
let terserOptions;
|
|
27
|
+
if (jsMinifier === types_1.JSMinifier.esbuild) {
|
|
28
|
+
minify = terser_webpack_plugin_1.default.esbuildMinify;
|
|
29
|
+
terserOptions = {
|
|
30
|
+
target: (0, getEsBuildTarget_1.getEsBuildTarget)({
|
|
31
|
+
targets: userConfig.targets || {},
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else if (jsMinifier === types_1.JSMinifier.terser) {
|
|
36
|
+
minify = terser_webpack_plugin_1.default.terserMinify;
|
|
37
|
+
}
|
|
38
|
+
else if (jsMinifier === types_1.JSMinifier.swc) {
|
|
39
|
+
minify = terser_webpack_plugin_1.default.swcMinify;
|
|
40
|
+
}
|
|
41
|
+
else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
|
|
42
|
+
minify = terser_webpack_plugin_1.default.uglifyJsMinify;
|
|
43
|
+
}
|
|
44
|
+
else if (jsMinifier !== types_1.JSMinifier.none) {
|
|
45
|
+
throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
|
|
46
|
+
}
|
|
47
|
+
terserOptions = {
|
|
48
|
+
...terserOptions,
|
|
49
|
+
...userConfig.jsMinifierOptions,
|
|
50
|
+
};
|
|
51
|
+
if (jsMinifier !== types_1.JSMinifier.none) {
|
|
52
|
+
config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
|
|
53
|
+
{
|
|
54
|
+
minify,
|
|
55
|
+
terserOptions,
|
|
56
|
+
},
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
if (cssMinifier === types_1.CSSMinifier.esbuild) {
|
|
60
|
+
config.optimization
|
|
61
|
+
.minimizer(`css-${cssMinifier}`)
|
|
62
|
+
.use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
|
|
63
|
+
}
|
|
64
|
+
else if (cssMinifier === types_1.CSSMinifier.cssnano) {
|
|
65
|
+
config.optimization
|
|
66
|
+
.minimizer(`css-${cssMinifier}`)
|
|
67
|
+
.use(css_minimizer_webpack_plugin_1.default, [
|
|
68
|
+
{
|
|
69
|
+
minimizerOptions: userConfig.cssMinifierOptions,
|
|
70
|
+
parallel: true,
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
|
|
75
|
+
config.optimization
|
|
76
|
+
.minimizer(`css-${cssMinifier}`)
|
|
77
|
+
.use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
|
|
78
|
+
}
|
|
79
|
+
else if (cssMinifier !== types_1.CSSMinifier.none) {
|
|
80
|
+
throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
|
|
81
|
+
}
|
|
90
82
|
}
|
|
91
83
|
exports.addCompressPlugin = addCompressPlugin;
|