@umijs/bundler-utoopack 4.6.53 → 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 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
@@ -445,7 +445,6 @@ async function getProdUtooPackConfig(opts) {
445
445
  return utooBundlerOpts;
446
446
  }
447
447
  async function getSSRUtooPackConfig(opts) {
448
- var _a;
449
448
  const utooBundlerOpts = await getProdUtooPackConfig({
450
449
  ...opts,
451
450
  clean: false,
@@ -455,49 +454,6 @@ async function getSSRUtooPackConfig(opts) {
455
454
  const entryName = (entry == null ? void 0 : entry[0]) || "umi.server";
456
455
  const entryPath = entry == null ? void 0 : entry[1];
457
456
  const filename = opts.useHash ? "[name].[contenthash:8].js" : (0, import_path.basename)(opts.serverBuildPath);
458
- const ssrAssetsLoader = {
459
- loader: require.resolve("./ssrAssetsLoader"),
460
- options: {
461
- cwd: opts.cwd
462
- }
463
- };
464
- const ssrStylesLoader = {
465
- loader: require.resolve("./ssrStylesLoader"),
466
- options: {
467
- cwd: opts.cwd
468
- }
469
- };
470
- const ssrAssetRules = [
471
- "*.png",
472
- "*.jpg",
473
- "*.jpeg",
474
- "*.gif",
475
- "*.webp",
476
- "*.avif",
477
- "*.ico",
478
- "*.woff",
479
- "*.woff2",
480
- "*.ttf",
481
- "*.eot",
482
- "*.mp3",
483
- "*.mp4"
484
- ].reduce((memo, key) => {
485
- memo[key] = {
486
- loaders: [ssrAssetsLoader],
487
- as: "*.js"
488
- };
489
- return memo;
490
- }, {});
491
- const ssrStyleRules = ["*.css", "*.less", "*.sass", "*.scss"].reduce(
492
- (memo, key) => {
493
- memo[key] = {
494
- loaders: [ssrStylesLoader],
495
- as: "*.js"
496
- };
497
- return memo;
498
- },
499
- {}
500
- );
501
457
  utooBundlerOpts.config = {
502
458
  ...utooBundlerOpts.config,
503
459
  entry: [
@@ -512,7 +468,8 @@ async function getSSRUtooPackConfig(opts) {
512
468
  path: (0, import_path.dirname)(opts.serverBuildPath),
513
469
  filename,
514
470
  chunkFilename: filename,
515
- clean: false,
471
+ ...opts.isDev ? { assetModuleFilename: "[name].[contenthash:8]" } : {},
472
+ clean: true,
516
473
  copy: [],
517
474
  publicPath: "/"
518
475
  },
@@ -520,14 +477,6 @@ async function getSSRUtooPackConfig(opts) {
520
477
  sourceMaps: false,
521
478
  stats: true,
522
479
  nodePolyfill: false,
523
- module: {
524
- ...utooBundlerOpts.config.module,
525
- rules: {
526
- ...(_a = utooBundlerOpts.config.module) == null ? void 0 : _a.rules,
527
- ...ssrAssetRules,
528
- ...ssrStyleRules
529
- }
530
- },
531
480
  optimization: {
532
481
  ...utooBundlerOpts.config.optimization,
533
482
  minify: false
@@ -623,6 +572,7 @@ async function getDevUtooPackConfig(opts) {
623
572
  emotion
624
573
  },
625
574
  define,
575
+ stats: true,
626
576
  // Windows persistent cache restore is currently unstable in utoopack dev.
627
577
  persistentCaching: getDefaultPersistentCaching(),
628
578
  nodePolyfill: true,
package/dist/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export declare function build(opts: IOpts): Promise<any>;
7
7
  export declare function buildSSR(opts: IOpts & {
8
8
  serverBuildPath: string;
9
9
  useHash?: boolean;
10
+ isDev?: boolean;
10
11
  }): Promise<any>;
11
12
  export declare function dev(opts: IDevOpts): Promise<any>;
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("File stats.json not found by utoopack dev");
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.6.53",
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.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.53",
24
- "@umijs/bundler-webpack": "4.6.53"
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;
@@ -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
- }
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export default function ssrStylesLoader(this: any, content: string | Buffer): string;
@@ -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
- }