@umijs/bundler-webpack 4.0.0-canary.20230224.1 → 4.0.0-canary.20230302.1
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.d.ts +1 -1
- package/dist/build.js +12 -15
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +5 -3
- package/dist/plugins/EsbuildMinifyFix.js +33 -10
- package/package.json +12 -12
package/dist/build.d.ts
CHANGED
package/dist/build.js
CHANGED
|
@@ -35,14 +35,16 @@ module.exports = __toCommonJS(build_exports);
|
|
|
35
35
|
var import_utils = require("@umijs/utils");
|
|
36
36
|
var import_path = require("path");
|
|
37
37
|
var import_webpack = __toESM(require("../compiled/webpack"));
|
|
38
|
-
var import_config = require("./config/config");
|
|
39
38
|
var import_types = require("./types");
|
|
39
|
+
var configModule = (0, import_utils.importLazy)(
|
|
40
|
+
require.resolve("./config/config")
|
|
41
|
+
);
|
|
40
42
|
async function build(opts) {
|
|
41
43
|
const cacheDirectoryPath = (0, import_path.resolve)(
|
|
42
44
|
opts.rootDir || opts.cwd,
|
|
43
45
|
opts.config.cacheDirectoryPath || "node_modules/.cache"
|
|
44
46
|
);
|
|
45
|
-
const webpackConfig = await
|
|
47
|
+
const webpackConfig = await configModule.getConfig({
|
|
46
48
|
cwd: opts.cwd,
|
|
47
49
|
rootDir: opts.rootDir,
|
|
48
50
|
env: import_types.Env.production,
|
|
@@ -74,26 +76,21 @@ async function build(opts) {
|
|
|
74
76
|
}
|
|
75
77
|
const compiler = (0, import_webpack.default)(webpackConfig);
|
|
76
78
|
let closeWatching;
|
|
77
|
-
const handler = (err, stats) => {
|
|
79
|
+
const handler = async (err, stats) => {
|
|
78
80
|
var _a;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const validErr = err || ((stats == null ? void 0 : stats.hasErrors()) ? new Error(stats.toString("errors-only")) : null);
|
|
82
|
+
await ((_a = opts.onBuildComplete) == null ? void 0 : _a.call(opts, {
|
|
83
|
+
err: validErr,
|
|
81
84
|
stats,
|
|
82
85
|
isFirstCompile,
|
|
83
86
|
time: stats ? stats.endTime - stats.startTime : null,
|
|
84
87
|
// pass close function to close watching
|
|
85
88
|
...opts.watch ? { close: closeWatching } : {}
|
|
86
|
-
});
|
|
89
|
+
}));
|
|
87
90
|
isFirstCompile = false;
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
if (stats) {
|
|
93
|
-
const errorMsg = stats.toString("errors-only");
|
|
94
|
-
esbuildCompressErrorHelper(errorMsg);
|
|
95
|
-
reject(new Error(errorMsg));
|
|
96
|
-
}
|
|
91
|
+
if (validErr) {
|
|
92
|
+
(stats == null ? void 0 : stats.hasErrors()) && esbuildCompressErrorHelper(validErr.toString());
|
|
93
|
+
reject(validErr);
|
|
97
94
|
} else {
|
|
98
95
|
resolve2(stats);
|
|
99
96
|
}
|
package/dist/dev.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { MFSU } from '@umijs/mfsu';
|
|
3
3
|
import type { Worker } from 'worker_threads';
|
|
4
4
|
import webpack from '../compiled/webpack';
|
|
5
|
-
import { IOpts as IConfigOpts } from './config/config';
|
|
5
|
+
import type { IOpts as IConfigOpts } from './config/config';
|
|
6
6
|
import { IConfig } from './types';
|
|
7
7
|
declare type IOpts = {
|
|
8
8
|
afterMiddlewares?: any[];
|
package/dist/dev.js
CHANGED
|
@@ -39,10 +39,12 @@ var import_utils = require("@umijs/utils");
|
|
|
39
39
|
var import_fs = require("fs");
|
|
40
40
|
var import_path = require("path");
|
|
41
41
|
var import_webpack = __toESM(require("../compiled/webpack"));
|
|
42
|
-
var import_config = require("./config/config");
|
|
43
42
|
var import_constants = require("./constants");
|
|
44
43
|
var import_server = require("./server/server");
|
|
45
44
|
var import_types = require("./types");
|
|
45
|
+
var configModule = (0, import_utils.importLazy)(
|
|
46
|
+
require.resolve("./config/config")
|
|
47
|
+
);
|
|
46
48
|
function ensureSerializableValue(obj) {
|
|
47
49
|
return JSON.parse(
|
|
48
50
|
JSON.stringify(
|
|
@@ -118,7 +120,7 @@ async function setup(opts) {
|
|
|
118
120
|
cwd: opts.cwd
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
|
-
const webpackConfig = await
|
|
123
|
+
const webpackConfig = await configModule.getConfig({
|
|
122
124
|
cwd: opts.cwd,
|
|
123
125
|
rootDir: opts.rootDir,
|
|
124
126
|
env: import_types.Env.development,
|
|
@@ -149,7 +151,7 @@ async function setup(opts) {
|
|
|
149
151
|
} : void 0,
|
|
150
152
|
pkg: opts.pkg
|
|
151
153
|
});
|
|
152
|
-
const depConfig = await
|
|
154
|
+
const depConfig = await configModule.getConfig({
|
|
153
155
|
cwd: opts.cwd,
|
|
154
156
|
rootDir: opts.rootDir,
|
|
155
157
|
env: import_types.Env.development,
|
|
@@ -24,6 +24,7 @@ __export(EsbuildMinifyFix_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(EsbuildMinifyFix_exports);
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
26
|
var import_webpack = require("../../compiled/webpack");
|
|
27
|
+
var JS_FILE_REG = /\.(js|mjs|cjs)$/;
|
|
27
28
|
var EsbuildMinifyFix = class {
|
|
28
29
|
constructor() {
|
|
29
30
|
this.name = `EsbuildMinifyFix`;
|
|
@@ -42,7 +43,7 @@ var EsbuildMinifyFix = class {
|
|
|
42
43
|
}
|
|
43
44
|
async minifyFix(compilation, assets) {
|
|
44
45
|
const matchObject = import_webpack.ModuleFilenameHelpers.matchObject.bind(void 0, {
|
|
45
|
-
include: [
|
|
46
|
+
include: [JS_FILE_REG]
|
|
46
47
|
});
|
|
47
48
|
const assetsForMinify = await Promise.all(
|
|
48
49
|
Object.keys(assets).filter((name) => {
|
|
@@ -53,6 +54,9 @@ var EsbuildMinifyFix = class {
|
|
|
53
54
|
if (!(info == null ? void 0 : info.minimized)) {
|
|
54
55
|
return false;
|
|
55
56
|
}
|
|
57
|
+
if (info == null ? void 0 : info.EsbuildMinifyFix) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
56
60
|
return true;
|
|
57
61
|
}).map(async (name) => {
|
|
58
62
|
const { info, source } = compilation.getAsset(name);
|
|
@@ -66,21 +70,40 @@ var EsbuildMinifyFix = class {
|
|
|
66
70
|
for (const asset of assetsForMinify) {
|
|
67
71
|
const { name, inputSource } = asset;
|
|
68
72
|
const { source, map } = inputSource.sourceAndMap();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!code.startsWith('"use strict";(self.') && !code.startsWith('(function(){"use strict";') && !code.startsWith("(self.webpack")) {
|
|
74
|
-
const bundle = new import_utils.MagicString(code);
|
|
73
|
+
const originCode = source.toString();
|
|
74
|
+
let newCode = originCode;
|
|
75
|
+
if (!newCode.startsWith('"use strict";(self.') && !newCode.startsWith('(function(){"use strict";') && !newCode.startsWith("(self.webpack")) {
|
|
76
|
+
const bundle = new import_utils.MagicString(newCode);
|
|
75
77
|
bundle.indent().prepend("!(function () {\n").append("}());");
|
|
76
|
-
|
|
78
|
+
newCode = bundle.toString();
|
|
77
79
|
const output = {};
|
|
78
80
|
if (map) {
|
|
79
|
-
|
|
81
|
+
const bundleMap = bundle.generateMap({
|
|
82
|
+
source: name,
|
|
83
|
+
file: `${name}.map`,
|
|
84
|
+
includeContent: true,
|
|
85
|
+
hires: true
|
|
86
|
+
});
|
|
87
|
+
const originMapAsString = JSON.stringify(map);
|
|
88
|
+
const mergedMap = (0, import_utils.remapping)(JSON.stringify(bundleMap), (file) => {
|
|
89
|
+
if (file === name) {
|
|
90
|
+
return originMapAsString;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
});
|
|
94
|
+
output.source = new SourceMapSource(
|
|
95
|
+
newCode,
|
|
96
|
+
name,
|
|
97
|
+
mergedMap,
|
|
98
|
+
originCode,
|
|
99
|
+
map,
|
|
100
|
+
true
|
|
101
|
+
);
|
|
80
102
|
} else {
|
|
81
|
-
output.source = new RawSource(
|
|
103
|
+
output.source = new RawSource(newCode);
|
|
82
104
|
}
|
|
83
105
|
compilation.updateAsset(name, output.source, {
|
|
106
|
+
...asset.info,
|
|
84
107
|
EsbuildMinifyFix: true
|
|
85
108
|
});
|
|
86
109
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20230302.1",
|
|
4
4
|
"description": "@umijs/bundler-webpack",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"test": "umi-scripts jest-turbo"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.5.
|
|
32
|
-
"@svgr/core": "6.
|
|
33
|
-
"@svgr/plugin-jsx": "^6.
|
|
34
|
-
"@svgr/plugin-svgo": "^6.
|
|
31
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
|
32
|
+
"@svgr/core": "6.5.1",
|
|
33
|
+
"@svgr/plugin-jsx": "^6.5.1",
|
|
34
|
+
"@svgr/plugin-svgo": "^6.5.1",
|
|
35
35
|
"@types/hapi__joi": "17.1.9",
|
|
36
|
-
"@umijs/babel-preset-umi": "4.0.0-canary.
|
|
37
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
36
|
+
"@umijs/babel-preset-umi": "4.0.0-canary.20230302.1",
|
|
37
|
+
"@umijs/bundler-utils": "4.0.0-canary.20230302.1",
|
|
38
38
|
"@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
|
|
39
|
-
"@umijs/mfsu": "4.0.0-canary.
|
|
40
|
-
"@umijs/utils": "4.0.0-canary.
|
|
39
|
+
"@umijs/mfsu": "4.0.0-canary.20230302.1",
|
|
40
|
+
"@umijs/utils": "4.0.0-canary.20230302.1",
|
|
41
41
|
"cors": "^2.8.5",
|
|
42
42
|
"css-loader": "6.7.1",
|
|
43
|
-
"es5-imcompatible-versions": "^0.1.
|
|
43
|
+
"es5-imcompatible-versions": "^0.1.78",
|
|
44
44
|
"fork-ts-checker-webpack-plugin": "7.3.0",
|
|
45
|
-
"jest-worker": "29.3
|
|
46
|
-
"lightningcss": "1.
|
|
45
|
+
"jest-worker": "29.4.3",
|
|
46
|
+
"lightningcss": "1.19.0",
|
|
47
47
|
"node-libs-browser": "2.2.1",
|
|
48
48
|
"postcss": "^8.4.21",
|
|
49
49
|
"postcss-preset-env": "7.5.0",
|