@umijs/bundler-utoopack 4.0.0-canary.20251124.1 → 4.0.0-canary.20260105.0

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.js CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/config.ts
@@ -26,6 +36,7 @@ module.exports = __toCommonJS(config_exports);
26
36
  var import_bundler_webpack = require("@umijs/bundler-webpack");
27
37
  var import_utils = require("@umijs/utils");
28
38
  var import_pack = require("@utoo/pack");
39
+ var import_path = require("path");
29
40
  function convertProcessEnvForUtoopack(webpackConfig) {
30
41
  var _a;
31
42
  let processEnvForUtoopack = {};
@@ -88,11 +99,14 @@ function getModularizeImports(extraBabelPlugins) {
88
99
  }
89
100
  function getNormalizedAlias(alias, rootDir) {
90
101
  const newAlias = { ...alias };
91
- const keysToExpand = ["react", "react-dom", "@", "@@"];
92
- for (const key of keysToExpand) {
93
- if (newAlias[key]) {
94
- newAlias[`${key}/*`] = `${newAlias[key]}/*`;
102
+ for (const [key, value] of Object.entries(newAlias)) {
103
+ if (key.endsWith("/*") || value.endsWith("/*") || key.endsWith("/") || value.endsWith("/") || key.endsWith("$")) {
104
+ continue;
95
105
  }
106
+ if ((0, import_path.extname)(value)) {
107
+ continue;
108
+ }
109
+ newAlias[`${key}/*`] = `${value}/*`;
96
110
  }
97
111
  newAlias[`${rootDir}/*`] = `${rootDir}/*`;
98
112
  return newAlias;
@@ -102,12 +116,22 @@ function getNormalizedExternals(externals) {
102
116
  (ret, [k, v]) => {
103
117
  if (Array.isArray(v)) {
104
118
  const [url, ...members] = v;
105
- ret[k] = {
106
- // ['antd', 'Button'] => `antd.Button`
107
- root: members.join("."),
108
- // `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
109
- script: url.replace("script ", "")
110
- };
119
+ const containsScript = url.startsWith("script");
120
+ const script = url.replace("script ", "");
121
+ if (containsScript) {
122
+ ret[k] = {
123
+ // ['antd', 'Button'] => `antd.Button`
124
+ root: members.join("."),
125
+ type: "script",
126
+ // `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
127
+ script
128
+ };
129
+ } else {
130
+ ret[k] = {
131
+ root: members.join("."),
132
+ script
133
+ };
134
+ }
111
135
  } else if (typeof v === "string") {
112
136
  ret[k] = v.replace(/^window(\s+|\.)/, "");
113
137
  } else {
@@ -117,6 +141,58 @@ function getNormalizedExternals(externals) {
117
141
  {}
118
142
  );
119
143
  }
144
+ function getSvgModuleRules(opts) {
145
+ const { svgr, svgo = {}, inlineLimit } = opts;
146
+ if (!svgr) {
147
+ return {};
148
+ }
149
+ return {
150
+ module: {
151
+ rules: {
152
+ "*.svg": {
153
+ loaders: [
154
+ {
155
+ loader: require.resolve("@umijs/bundler-webpack/dist/loader/svgr"),
156
+ options: {
157
+ svgoConfig: {
158
+ plugins: [
159
+ {
160
+ name: "preset-default",
161
+ params: {
162
+ overrides: {
163
+ removeTitle: false
164
+ }
165
+ }
166
+ },
167
+ "prefixIds"
168
+ ],
169
+ ...typeof svgo === "object" ? svgo : {}
170
+ },
171
+ ...svgr,
172
+ svgo: !!svgo
173
+ },
174
+ condition: {
175
+ all: [
176
+ // Exclude node_modules (similar to excluding non-source files)
177
+ { not: "foreign" },
178
+ { path: /\.[jt]sx?$/ }
179
+ ]
180
+ }
181
+ },
182
+ {
183
+ loader: require.resolve("@umijs/bundler-webpack/compiled/url-loader"),
184
+ options: {
185
+ limit: inlineLimit,
186
+ fallback: require.resolve("@umijs/bundler-webpack/compiled/file-loader")
187
+ }
188
+ }
189
+ ],
190
+ as: "*.js"
191
+ }
192
+ }
193
+ }
194
+ };
195
+ }
120
196
  async function getProdUtooPackConfig(opts) {
121
197
  var _a;
122
198
  const webpackConfig = await (0, import_bundler_webpack.getConfig)({
@@ -143,7 +219,7 @@ async function getProdUtooPackConfig(opts) {
143
219
  });
144
220
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
145
221
  ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
146
- compatMode: true
222
+ webpackMode: true
147
223
  });
148
224
  const extraBabelPlugins = [
149
225
  ...opts.extraBabelPlugins || [],
@@ -154,7 +230,11 @@ async function getProdUtooPackConfig(opts) {
154
230
  const {
155
231
  publicPath,
156
232
  runtimePublicPath,
157
- externals: userExternals
233
+ externals: userExternals,
234
+ copy = [],
235
+ svgr,
236
+ svgo = {},
237
+ inlineLimit
158
238
  } = opts.config;
159
239
  utooBundlerOpts = {
160
240
  ...utooBundlerOpts,
@@ -163,7 +243,8 @@ async function getProdUtooPackConfig(opts) {
163
243
  {
164
244
  output: {
165
245
  clean: opts.clean,
166
- publicPath: runtimePublicPath ? "runtime" : publicPath || "/"
246
+ publicPath: runtimePublicPath ? "runtime" : publicPath || "/",
247
+ ...opts.disableCopy ? { copy: [] } : { copy: ["public"].concat(copy) }
167
248
  },
168
249
  optimization: {
169
250
  modularizeImports,
@@ -188,7 +269,8 @@ async function getProdUtooPackConfig(opts) {
188
269
  "process.env": JSON.stringify(processEnvForUtoopack)
189
270
  },
190
271
  nodePolyfill: true,
191
- externals: getNormalizedExternals(userExternals)
272
+ externals: getNormalizedExternals(userExternals),
273
+ ...getSvgModuleRules({ svgr, svgo, inlineLimit })
192
274
  },
193
275
  opts.config.utoopack || {}
194
276
  )
@@ -221,7 +303,7 @@ async function getDevUtooPackConfig(opts) {
221
303
  });
222
304
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
223
305
  ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
224
- compatMode: true
306
+ webpackMode: true
225
307
  });
226
308
  const extraBabelPlugins = [
227
309
  ...opts.extraBabelPlugins || [],
@@ -232,8 +314,14 @@ async function getDevUtooPackConfig(opts) {
232
314
  const {
233
315
  publicPath,
234
316
  runtimePublicPath,
235
- externals: userExternals
317
+ externals: userExternals,
318
+ copy = [],
319
+ svgr,
320
+ svgo = {},
321
+ inlineLimit
236
322
  } = opts.config;
323
+ const normalizedExternals = getNormalizedExternals(userExternals);
324
+ debugger;
237
325
  utooBundlerOpts = {
238
326
  ...utooBundlerOpts,
239
327
  config: import_utils.lodash.merge(
@@ -242,7 +330,8 @@ async function getDevUtooPackConfig(opts) {
242
330
  output: {
243
331
  // utoopack 的 dev 需要默认清空产物目录
244
332
  clean: opts.clean === void 0 ? true : opts.clean,
245
- publicPath: runtimePublicPath ? "runtime" : publicPath || "/"
333
+ publicPath: runtimePublicPath ? "runtime" : publicPath || "/",
334
+ ...opts.disableCopy ? { copy: [] } : { copy: ["public"].concat(copy) }
246
335
  },
247
336
  resolve: {
248
337
  alias: getNormalizedAlias(
@@ -266,7 +355,8 @@ async function getDevUtooPackConfig(opts) {
266
355
  "process.env": JSON.stringify(processEnvForUtoopack)
267
356
  },
268
357
  nodePolyfill: true,
269
- externals: getNormalizedExternals(userExternals)
358
+ externals: normalizedExternals,
359
+ ...getSvgModuleRules({ svgr, svgo, inlineLimit })
270
360
  },
271
361
  opts.config.utoopack || {}
272
362
  ),
package/dist/index.js CHANGED
@@ -186,7 +186,7 @@ async function dev(opts) {
186
186
  );
187
187
  stats = JSON.parse(import_fs.default.readFileSync(statsPath, "utf-8"));
188
188
  } catch (e) {
189
- throw new Error("Stats.json not found by utoopack dev");
189
+ throw new Error("File stats.json not found by utoopack dev");
190
190
  }
191
191
  stats.hasErrors = () => false;
192
192
  stats.toJson = () => stats;
@@ -204,7 +204,8 @@ async function dev(opts) {
204
204
  try {
205
205
  await utooPackServe(utooPackConfig, cwd, rootDir, {
206
206
  port: utooServePort,
207
- hostname: opts.host
207
+ hostname: "127.0.0.1",
208
+ logServerInfo: false
208
209
  });
209
210
  const stats = createStatsObject();
210
211
  await (onDevCompileDone == null ? void 0 : onDevCompileDone({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.0.0-canary.20251124.1",
3
+ "version": "4.0.0-canary.20260105.0",
4
4
  "description": "@umijs/bundler-utoopack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,14 +8,14 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "@utoo/pack": "0.0.1-alpha.73",
11
+ "@utoo/pack": "1.1.16-alpha.0",
12
12
  "compression": "^1.7.4",
13
13
  "connect-history-api-fallback": "^2.0.0",
14
14
  "cors": "^2.8.5",
15
15
  "express": "^4.18.2",
16
16
  "express-http-proxy": "^2.1.1",
17
- "@umijs/bundler-utils": "4.0.0-canary.20251124.1",
18
- "@umijs/bundler-webpack": "4.0.0-canary.20251124.1"
17
+ "@umijs/bundler-utils": "4.0.0-canary.20260105.0",
18
+ "@umijs/bundler-webpack": "4.0.0-canary.20260105.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "father": "4.1.5"