@umijs/bundler-utoopack 4.6.53 → 4.6.55

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,7 @@ async function getSSRUtooPackConfig(opts) {
512
468
  path: (0, import_path.dirname)(opts.serverBuildPath),
513
469
  filename,
514
470
  chunkFilename: filename,
515
- clean: false,
471
+ clean: true,
516
472
  copy: [],
517
473
  publicPath: "/"
518
474
  },
@@ -520,14 +476,6 @@ async function getSSRUtooPackConfig(opts) {
520
476
  sourceMaps: false,
521
477
  stats: true,
522
478
  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
479
  optimization: {
532
480
  ...utooBundlerOpts.config.optimization,
533
481
  minify: false
@@ -623,6 +571,7 @@ async function getDevUtooPackConfig(opts) {
623
571
  emotion
624
572
  },
625
573
  define,
574
+ stats: true,
626
575
  // Windows persistent cache restore is currently unstable in utoopack dev.
627
576
  persistentCaching: getDefaultPersistentCaching(),
628
577
  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/dist/util.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { WebpackConfig } from '@utoo/pack';
1
2
  declare type IDevBannerOpts = {
2
3
  duration?: number;
3
4
  host?: string;
@@ -13,6 +14,26 @@ declare type IBuildBannerOpts = {
13
14
  packVersion?: string;
14
15
  };
15
16
  export declare function getPackVersion(packVersion?: string): any;
17
+ export declare function getCssOutputFilenames(opts: {
18
+ entry: Record<string, string>;
19
+ config: Record<string, any>;
20
+ webpackConfig: WebpackConfig;
21
+ useHash: boolean;
22
+ }): {
23
+ cssChunkFilename: string;
24
+ cssFilename?: string | undefined;
25
+ };
26
+ export declare function getSSRCssSplitChunks(config: Record<string, any>): {
27
+ splitChunks?: undefined;
28
+ } | {
29
+ splitChunks: {
30
+ css: {
31
+ minChunkSize: number;
32
+ maxChunkCountPerGroup: number;
33
+ maxMergeChunkSize: number;
34
+ };
35
+ };
36
+ };
16
37
  export declare function getDevBanner({ protocol, host, port, ip, packVersion, duration, }: IDevBannerOpts): string;
17
38
  export declare function getBuildBanner({ packVersion, duration, outputPath, assetCount, }: IBuildBannerOpts): string;
18
39
  export {};
package/dist/util.js CHANGED
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var util_exports = {};
21
21
  __export(util_exports, {
22
22
  getBuildBanner: () => getBuildBanner,
23
+ getCssOutputFilenames: () => getCssOutputFilenames,
23
24
  getDevBanner: () => getDevBanner,
24
- getPackVersion: () => getPackVersion
25
+ getPackVersion: () => getPackVersion,
26
+ getSSRCssSplitChunks: () => getSSRCssSplitChunks
25
27
  });
26
28
  module.exports = __toCommonJS(util_exports);
27
29
  var import_utils = require("@umijs/utils");
@@ -56,6 +58,67 @@ function formatDuration(duration) {
56
58
  }
57
59
  return `${Math.max(0, Math.round(duration))}ms`;
58
60
  }
61
+ function normalizeUtoopackFilenameTemplate(filename) {
62
+ return filename.replace(
63
+ /\[(?:hash|chunkhash)(?::(\d+))?\]/g,
64
+ (_, length) => `[contenthash${length ? `:${length}` : ""}]`
65
+ );
66
+ }
67
+ function getMiniCssExtractPluginOptions(webpackConfig) {
68
+ var _a;
69
+ const plugin = (_a = webpackConfig.plugins) == null ? void 0 : _a.find((p) => {
70
+ var _a2;
71
+ return p && typeof p === "object" && ((_a2 = p.constructor) == null ? void 0 : _a2.name) === "MiniCssExtractPlugin";
72
+ });
73
+ return plugin == null ? void 0 : plugin.options;
74
+ }
75
+ function getEntryCssFilename(entry, filenameTemplate, replaceName) {
76
+ const normalizedFilenameTemplate = normalizeUtoopackFilenameTemplate(filenameTemplate);
77
+ if (!replaceName) {
78
+ return normalizedFilenameTemplate;
79
+ }
80
+ const entryNames = Object.keys(entry || {});
81
+ if (entryNames.length !== 1) {
82
+ return void 0;
83
+ }
84
+ return normalizedFilenameTemplate.replace(/\[name\]/g, entryNames[0]);
85
+ }
86
+ function getCssOutputFilenames(opts) {
87
+ const miniCssExtractOptions = getMiniCssExtractPluginOptions(
88
+ opts.webpackConfig
89
+ );
90
+ const hash = opts.useHash ? ".[contenthash:8]" : "";
91
+ const cssFilenameTemplate = typeof (miniCssExtractOptions == null ? void 0 : miniCssExtractOptions.filename) === "string" ? miniCssExtractOptions.filename : `[name]${hash}.css`;
92
+ let cssChunkFilenameTemplate = typeof (miniCssExtractOptions == null ? void 0 : miniCssExtractOptions.chunkFilename) === "string" ? miniCssExtractOptions.chunkFilename : void 0;
93
+ if (!cssChunkFilenameTemplate) {
94
+ cssChunkFilenameTemplate = opts.config.ssr ? `umi${hash}.css` : `[name]${hash}.chunk.css`;
95
+ }
96
+ const cssFilename = getEntryCssFilename(
97
+ opts.entry,
98
+ cssFilenameTemplate,
99
+ !!opts.config.ssr
100
+ );
101
+ return {
102
+ ...cssFilename ? { cssFilename } : {},
103
+ cssChunkFilename: normalizeUtoopackFilenameTemplate(
104
+ cssChunkFilenameTemplate
105
+ )
106
+ };
107
+ }
108
+ function getSSRCssSplitChunks(config) {
109
+ if (!config.ssr) {
110
+ return {};
111
+ }
112
+ return {
113
+ splitChunks: {
114
+ css: {
115
+ minChunkSize: 1e8,
116
+ maxChunkCountPerGroup: 1,
117
+ maxMergeChunkSize: 1e8
118
+ }
119
+ }
120
+ };
121
+ }
59
122
  function getDevBanner({
60
123
  protocol,
61
124
  host,
@@ -125,6 +188,8 @@ function getBuildBanner({
125
188
  // Annotate the CommonJS export names for ESM import in node:
126
189
  0 && (module.exports = {
127
190
  getBuildBanner,
191
+ getCssOutputFilenames,
128
192
  getDevBanner,
129
- getPackVersion
193
+ getPackVersion,
194
+ getSSRCssSplitChunks
130
195
  });
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.55",
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.7",
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.55",
24
+ "@umijs/bundler-webpack": "4.6.55"
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
- }