@umijs/bundler-utoopack 4.6.52 → 4.6.54
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/config.d.ts +1 -0
- package/dist/config.js +107 -58
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -5
- package/dist/types.d.ts +1 -0
- package/package.json +4 -4
- package/dist/ssrAssetsLoader.d.ts +0 -1
- package/dist/ssrAssetsLoader.js +0 -35
- package/dist/ssrStylesLoader.d.ts +0 -2
- package/dist/ssrStylesLoader.js +0 -54
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare function getProdUtooPackConfig(opts: IOpts): Promise<BundleOption
|
|
|
6
6
|
export declare function getSSRUtooPackConfig(opts: IOpts & {
|
|
7
7
|
serverBuildPath: string;
|
|
8
8
|
useHash?: boolean;
|
|
9
|
+
isDev?: boolean;
|
|
9
10
|
}): Promise<BundleOptions>;
|
|
10
11
|
export declare type IDevOpts = {
|
|
11
12
|
afterMiddlewares?: any[];
|
package/dist/config.js
CHANGED
|
@@ -98,6 +98,103 @@ function getModularizeImports(extraBabelPlugins) {
|
|
|
98
98
|
{}
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
|
+
function getBabelPluginName(plugin) {
|
|
102
|
+
const name = Array.isArray(plugin) ? plugin[0] : plugin;
|
|
103
|
+
return typeof name === "string" ? name : "";
|
|
104
|
+
}
|
|
105
|
+
function isModularizeImportPlugin(plugin) {
|
|
106
|
+
return /^import$|babel-plugin-import/.test(getBabelPluginName(plugin));
|
|
107
|
+
}
|
|
108
|
+
function isEmotionBabelPlugin(plugin) {
|
|
109
|
+
const name = getBabelPluginName(plugin);
|
|
110
|
+
return name === "@emotion" || name.endsWith("@emotion/babel-plugin");
|
|
111
|
+
}
|
|
112
|
+
function getExtraBabelPlugins(opts) {
|
|
113
|
+
return [
|
|
114
|
+
...opts.beforeBabelPlugins || [],
|
|
115
|
+
...opts.extraBabelPlugins || [],
|
|
116
|
+
...opts.config.extraBabelPlugins || []
|
|
117
|
+
].filter(Boolean).filter(isSerializableBabelItem);
|
|
118
|
+
}
|
|
119
|
+
function getExtraBabelPresets(opts) {
|
|
120
|
+
return [
|
|
121
|
+
...opts.beforeBabelPresets || [],
|
|
122
|
+
...opts.extraBabelPresets || [],
|
|
123
|
+
...opts.config.extraBabelPresets || []
|
|
124
|
+
].filter(Boolean).filter(isSerializableBabelItem);
|
|
125
|
+
}
|
|
126
|
+
function dropUndefinedValues(value) {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
return value.map(dropUndefinedValues);
|
|
129
|
+
}
|
|
130
|
+
if (value && typeof value === "object") {
|
|
131
|
+
return Object.fromEntries(
|
|
132
|
+
Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => [key, dropUndefinedValues(item)])
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function isSerializableBabelItem(item) {
|
|
138
|
+
const normalized = dropUndefinedValues(item);
|
|
139
|
+
try {
|
|
140
|
+
return import_utils.lodash.isEqual(normalized, JSON.parse(JSON.stringify(normalized)));
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function getExtraBabelModuleRules(opts) {
|
|
146
|
+
var _a;
|
|
147
|
+
if (((_a = opts.config.utoopack) == null ? void 0 : _a.babelLoader) !== true) {
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
const plugins = getExtraBabelPlugins(opts).filter((plugin) => {
|
|
151
|
+
return !isModularizeImportPlugin(plugin) && !isEmotionBabelPlugin(plugin);
|
|
152
|
+
});
|
|
153
|
+
const extraPresets = getExtraBabelPresets(opts);
|
|
154
|
+
if (!plugins.length && !extraPresets.length) {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
const presets = [opts.babelPreset, ...extraPresets].filter(Boolean);
|
|
158
|
+
const rule = {
|
|
159
|
+
condition: {
|
|
160
|
+
all: [
|
|
161
|
+
{ not: "foreign" },
|
|
162
|
+
{
|
|
163
|
+
not: {
|
|
164
|
+
path: /[\\/]src[\\/]\.umi(?:-[^\\/]*)?[\\/]/
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
loaders: [
|
|
170
|
+
{
|
|
171
|
+
loader: require.resolve("@umijs/bundler-webpack/compiled/babel-loader"),
|
|
172
|
+
options: dropUndefinedValues({
|
|
173
|
+
sourceType: "unambiguous",
|
|
174
|
+
babelrc: false,
|
|
175
|
+
configFile: false,
|
|
176
|
+
cacheDirectory: false,
|
|
177
|
+
browserslistConfigFile: false,
|
|
178
|
+
targets: opts.config.targets,
|
|
179
|
+
customize: opts.config.babelLoaderCustomize,
|
|
180
|
+
presets,
|
|
181
|
+
plugins
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
as: "*.js"
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
module: {
|
|
189
|
+
rules: Object.fromEntries(
|
|
190
|
+
["js", "mjs", "cjs", "jsx", "ts", "tsx"].map((ext) => [
|
|
191
|
+
`**/src/**/*.${ext}`,
|
|
192
|
+
rule
|
|
193
|
+
])
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
101
198
|
function getNormalizedAlias(alias, rootDir) {
|
|
102
199
|
const newAlias = { ...alias };
|
|
103
200
|
for (const [key, value] of Object.entries(newAlias)) {
|
|
@@ -251,7 +348,7 @@ function mergeExtraPostcssPlugins(postcssConfig, extraPlugins = []) {
|
|
|
251
348
|
}, postcssConfig);
|
|
252
349
|
}
|
|
253
350
|
function getUserUtoopackConfig(utoopackConfig = {}) {
|
|
254
|
-
return import_utils.lodash.omit(utoopackConfig, ["root"]);
|
|
351
|
+
return import_utils.lodash.omit(utoopackConfig, ["babelLoader", "root"]);
|
|
255
352
|
}
|
|
256
353
|
function getDefaultPersistentCaching() {
|
|
257
354
|
return process.platform !== "win32";
|
|
@@ -338,16 +435,16 @@ async function getProdUtooPackConfig(opts) {
|
|
|
338
435
|
define,
|
|
339
436
|
nodePolyfill: true,
|
|
340
437
|
mdx: !!mdx,
|
|
341
|
-
externals: getNormalizedExternals(userExternals)
|
|
342
|
-
...getSvgModuleRules({ svgr, svgo, inlineLimit })
|
|
438
|
+
externals: getNormalizedExternals(userExternals)
|
|
343
439
|
},
|
|
440
|
+
getExtraBabelModuleRules(opts),
|
|
441
|
+
getSvgModuleRules({ svgr, svgo, inlineLimit }),
|
|
344
442
|
userUtoopackConfig
|
|
345
443
|
)
|
|
346
444
|
};
|
|
347
445
|
return utooBundlerOpts;
|
|
348
446
|
}
|
|
349
447
|
async function getSSRUtooPackConfig(opts) {
|
|
350
|
-
var _a;
|
|
351
448
|
const utooBundlerOpts = await getProdUtooPackConfig({
|
|
352
449
|
...opts,
|
|
353
450
|
clean: false,
|
|
@@ -357,49 +454,6 @@ async function getSSRUtooPackConfig(opts) {
|
|
|
357
454
|
const entryName = (entry == null ? void 0 : entry[0]) || "umi.server";
|
|
358
455
|
const entryPath = entry == null ? void 0 : entry[1];
|
|
359
456
|
const filename = opts.useHash ? "[name].[contenthash:8].js" : (0, import_path.basename)(opts.serverBuildPath);
|
|
360
|
-
const ssrAssetsLoader = {
|
|
361
|
-
loader: require.resolve("./ssrAssetsLoader"),
|
|
362
|
-
options: {
|
|
363
|
-
cwd: opts.cwd
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const ssrStylesLoader = {
|
|
367
|
-
loader: require.resolve("./ssrStylesLoader"),
|
|
368
|
-
options: {
|
|
369
|
-
cwd: opts.cwd
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
const ssrAssetRules = [
|
|
373
|
-
"*.png",
|
|
374
|
-
"*.jpg",
|
|
375
|
-
"*.jpeg",
|
|
376
|
-
"*.gif",
|
|
377
|
-
"*.webp",
|
|
378
|
-
"*.avif",
|
|
379
|
-
"*.ico",
|
|
380
|
-
"*.woff",
|
|
381
|
-
"*.woff2",
|
|
382
|
-
"*.ttf",
|
|
383
|
-
"*.eot",
|
|
384
|
-
"*.mp3",
|
|
385
|
-
"*.mp4"
|
|
386
|
-
].reduce((memo, key) => {
|
|
387
|
-
memo[key] = {
|
|
388
|
-
loaders: [ssrAssetsLoader],
|
|
389
|
-
as: "*.js"
|
|
390
|
-
};
|
|
391
|
-
return memo;
|
|
392
|
-
}, {});
|
|
393
|
-
const ssrStyleRules = ["*.css", "*.less", "*.sass", "*.scss"].reduce(
|
|
394
|
-
(memo, key) => {
|
|
395
|
-
memo[key] = {
|
|
396
|
-
loaders: [ssrStylesLoader],
|
|
397
|
-
as: "*.js"
|
|
398
|
-
};
|
|
399
|
-
return memo;
|
|
400
|
-
},
|
|
401
|
-
{}
|
|
402
|
-
);
|
|
403
457
|
utooBundlerOpts.config = {
|
|
404
458
|
...utooBundlerOpts.config,
|
|
405
459
|
entry: [
|
|
@@ -414,7 +468,8 @@ async function getSSRUtooPackConfig(opts) {
|
|
|
414
468
|
path: (0, import_path.dirname)(opts.serverBuildPath),
|
|
415
469
|
filename,
|
|
416
470
|
chunkFilename: filename,
|
|
417
|
-
|
|
471
|
+
...opts.isDev ? { assetModuleFilename: "[name].[contenthash:8]" } : {},
|
|
472
|
+
clean: true,
|
|
418
473
|
copy: [],
|
|
419
474
|
publicPath: "/"
|
|
420
475
|
},
|
|
@@ -422,14 +477,6 @@ async function getSSRUtooPackConfig(opts) {
|
|
|
422
477
|
sourceMaps: false,
|
|
423
478
|
stats: true,
|
|
424
479
|
nodePolyfill: false,
|
|
425
|
-
module: {
|
|
426
|
-
...utooBundlerOpts.config.module,
|
|
427
|
-
rules: {
|
|
428
|
-
...(_a = utooBundlerOpts.config.module) == null ? void 0 : _a.rules,
|
|
429
|
-
...ssrAssetRules,
|
|
430
|
-
...ssrStyleRules
|
|
431
|
-
}
|
|
432
|
-
},
|
|
433
480
|
optimization: {
|
|
434
481
|
...utooBundlerOpts.config.optimization,
|
|
435
482
|
minify: false
|
|
@@ -525,6 +572,7 @@ async function getDevUtooPackConfig(opts) {
|
|
|
525
572
|
emotion
|
|
526
573
|
},
|
|
527
574
|
define,
|
|
575
|
+
stats: true,
|
|
528
576
|
// Windows persistent cache restore is currently unstable in utoopack dev.
|
|
529
577
|
persistentCaching: getDefaultPersistentCaching(),
|
|
530
578
|
nodePolyfill: true,
|
|
@@ -535,9 +583,10 @@ async function getDevUtooPackConfig(opts) {
|
|
|
535
583
|
react: {
|
|
536
584
|
absoluteSourceFilename: true
|
|
537
585
|
}
|
|
538
|
-
} : {}
|
|
539
|
-
...getSvgModuleRules({ svgr, svgo, inlineLimit })
|
|
586
|
+
} : {}
|
|
540
587
|
},
|
|
588
|
+
getExtraBabelModuleRules(opts),
|
|
589
|
+
getSvgModuleRules({ svgr, svgo, inlineLimit }),
|
|
541
590
|
userUtoopackConfig
|
|
542
591
|
),
|
|
543
592
|
watch: {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -252,14 +252,16 @@ async function dev(opts) {
|
|
|
252
252
|
const createStatsObject = () => {
|
|
253
253
|
var _a;
|
|
254
254
|
let stats;
|
|
255
|
+
const statsPath = import_path.default.join(
|
|
256
|
+
((_a = utooPackConfig.config.output) == null ? void 0 : _a.path) || "dist",
|
|
257
|
+
"stats.json"
|
|
258
|
+
);
|
|
255
259
|
try {
|
|
256
|
-
const statsPath = import_path.default.join(
|
|
257
|
-
((_a = utooPackConfig.config.output) == null ? void 0 : _a.path) || "dist",
|
|
258
|
-
"stats.json"
|
|
259
|
-
);
|
|
260
260
|
stats = JSON.parse(import_fs.default.readFileSync(statsPath, "utf-8"));
|
|
261
261
|
} catch (e) {
|
|
262
|
-
throw new Error(
|
|
262
|
+
throw new Error(
|
|
263
|
+
`File stats.json not found by utoopack dev at ${statsPath}: ${e.message}`
|
|
264
|
+
);
|
|
263
265
|
}
|
|
264
266
|
stats.hasErrors = () => false;
|
|
265
267
|
stats.toJson = () => stats;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-utoopack",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.54",
|
|
4
4
|
"description": "@umijs/bundler-utoopack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@utoo/pack": "1.4.
|
|
11
|
+
"@utoo/pack": "1.4.6",
|
|
12
12
|
"compression": "^1.7.4",
|
|
13
13
|
"connect-history-api-fallback": "^2.0.0",
|
|
14
14
|
"cors": "^2.8.5",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"resolve-url-loader": "5.0.0",
|
|
21
21
|
"sass": "1.54.0",
|
|
22
22
|
"sass-loader": "13.2.0",
|
|
23
|
-
"@umijs/bundler-utils": "4.6.
|
|
24
|
-
"@umijs/bundler-webpack": "4.6.
|
|
23
|
+
"@umijs/bundler-utils": "4.6.54",
|
|
24
|
+
"@umijs/bundler-webpack": "4.6.54"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"father": "4.1.5"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function ssrAssetsLoader(this: any): string;
|
package/dist/ssrAssetsLoader.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/ssrAssetsLoader.ts
|
|
20
|
-
var ssrAssetsLoader_exports = {};
|
|
21
|
-
__export(ssrAssetsLoader_exports, {
|
|
22
|
-
default: () => ssrAssetsLoader
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(ssrAssetsLoader_exports);
|
|
25
|
-
var import_utils = require("@umijs/utils");
|
|
26
|
-
function ensureLastSlash(path) {
|
|
27
|
-
return path.endsWith("/") ? path : path + "/";
|
|
28
|
-
}
|
|
29
|
-
function ssrAssetsLoader() {
|
|
30
|
-
var _a;
|
|
31
|
-
const options = ((_a = this.getOptions) == null ? void 0 : _a.call(this)) || {};
|
|
32
|
-
const cwd = (0, import_utils.winPath)(options.cwd || this.rootContext || process.cwd());
|
|
33
|
-
const filename = (0, import_utils.winPath)(this.resourcePath).replace(ensureLastSlash(cwd), "");
|
|
34
|
-
return `export default global.g_getAssets(${JSON.stringify(filename)});`;
|
|
35
|
-
}
|
package/dist/ssrStylesLoader.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/ssrStylesLoader.ts
|
|
20
|
-
var ssrStylesLoader_exports = {};
|
|
21
|
-
__export(ssrStylesLoader_exports, {
|
|
22
|
-
default: () => ssrStylesLoader
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(ssrStylesLoader_exports);
|
|
25
|
-
var import_utils = require("@umijs/utils");
|
|
26
|
-
function ensureLastSlash(path) {
|
|
27
|
-
return path.endsWith("/") ? path : path + "/";
|
|
28
|
-
}
|
|
29
|
-
function hashString(str) {
|
|
30
|
-
let hash = Buffer.from(str).toString("base64").replace(/=/g, "");
|
|
31
|
-
hash = hash.substring(hash.length - 5);
|
|
32
|
-
return hash;
|
|
33
|
-
}
|
|
34
|
-
function getClassNames(code) {
|
|
35
|
-
const classNames = /* @__PURE__ */ new Set();
|
|
36
|
-
const regexp = /\.([_a-zA-Z][\w-]*)/g;
|
|
37
|
-
let match;
|
|
38
|
-
while (match = regexp.exec(code)) {
|
|
39
|
-
classNames.add(match[1]);
|
|
40
|
-
}
|
|
41
|
-
return Array.from(classNames);
|
|
42
|
-
}
|
|
43
|
-
function ssrStylesLoader(content) {
|
|
44
|
-
var _a;
|
|
45
|
-
const options = ((_a = this.getOptions) == null ? void 0 : _a.call(this)) || {};
|
|
46
|
-
const cwd = (0, import_utils.winPath)(options.cwd || this.rootContext || process.cwd());
|
|
47
|
-
const filename = (0, import_utils.winPath)(this.resourcePath).replace(ensureLastSlash(cwd), "");
|
|
48
|
-
const code = Buffer.isBuffer(content) ? content.toString() : content;
|
|
49
|
-
const cssModuleObject = getClassNames(code).sort().reduce((memo, key) => {
|
|
50
|
-
memo[key] = `${key}___${hashString(`${filename}@${key}`)}`;
|
|
51
|
-
return memo;
|
|
52
|
-
}, {});
|
|
53
|
-
return `export default ${JSON.stringify(cssModuleObject)};`;
|
|
54
|
-
}
|