@umijs/bundler-utoopack 4.0.0-canary.20251209.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 +125 -12
- package/dist/index.js +2 -1
- package/package.json +4 -4
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
|
|
@@ -27,6 +37,27 @@ var import_bundler_webpack = require("@umijs/bundler-webpack");
|
|
|
27
37
|
var import_utils = require("@umijs/utils");
|
|
28
38
|
var import_pack = require("@utoo/pack");
|
|
29
39
|
var import_path = require("path");
|
|
40
|
+
function convertProcessEnvForUtoopack(webpackConfig) {
|
|
41
|
+
var _a;
|
|
42
|
+
let processEnvForUtoopack = {};
|
|
43
|
+
if (webpackConfig.plugins) {
|
|
44
|
+
const definePlugin = webpackConfig.plugins.find(
|
|
45
|
+
(plugin) => plugin.constructor.name === "DefinePlugin"
|
|
46
|
+
);
|
|
47
|
+
if ((_a = definePlugin == null ? void 0 : definePlugin.definitions) == null ? void 0 : _a["process.env"]) {
|
|
48
|
+
for (const [key, value] of Object.entries(
|
|
49
|
+
definePlugin.definitions["process.env"]
|
|
50
|
+
)) {
|
|
51
|
+
if (typeof value === "string" && value.startsWith('"') && value.endsWith('"')) {
|
|
52
|
+
processEnvForUtoopack[key] = JSON.parse(value);
|
|
53
|
+
} else {
|
|
54
|
+
processEnvForUtoopack[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return processEnvForUtoopack;
|
|
60
|
+
}
|
|
30
61
|
function getModularizeImports(extraBabelPlugins) {
|
|
31
62
|
return extraBabelPlugins.filter((p) => /^import$|babel-plugin-import/.test(p[0])).reduce(
|
|
32
63
|
(acc, [_, v]) => {
|
|
@@ -85,12 +116,22 @@ function getNormalizedExternals(externals) {
|
|
|
85
116
|
(ret, [k, v]) => {
|
|
86
117
|
if (Array.isArray(v)) {
|
|
87
118
|
const [url, ...members] = v;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
}
|
|
94
135
|
} else if (typeof v === "string") {
|
|
95
136
|
ret[k] = v.replace(/^window(\s+|\.)/, "");
|
|
96
137
|
} else {
|
|
@@ -100,6 +141,58 @@ function getNormalizedExternals(externals) {
|
|
|
100
141
|
{}
|
|
101
142
|
);
|
|
102
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
|
+
}
|
|
103
196
|
async function getProdUtooPackConfig(opts) {
|
|
104
197
|
var _a;
|
|
105
198
|
const webpackConfig = await (0, import_bundler_webpack.getConfig)({
|
|
@@ -126,18 +219,22 @@ async function getProdUtooPackConfig(opts) {
|
|
|
126
219
|
});
|
|
127
220
|
let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
|
|
128
221
|
...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
|
|
129
|
-
|
|
222
|
+
webpackMode: true
|
|
130
223
|
});
|
|
131
224
|
const extraBabelPlugins = [
|
|
132
225
|
...opts.extraBabelPlugins || [],
|
|
133
226
|
...opts.config.extraBabelPlugins || []
|
|
134
227
|
];
|
|
135
228
|
const modularizeImports = getModularizeImports(extraBabelPlugins);
|
|
229
|
+
const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
|
|
136
230
|
const {
|
|
137
231
|
publicPath,
|
|
138
232
|
runtimePublicPath,
|
|
139
233
|
externals: userExternals,
|
|
140
|
-
copy = []
|
|
234
|
+
copy = [],
|
|
235
|
+
svgr,
|
|
236
|
+
svgo = {},
|
|
237
|
+
inlineLimit
|
|
141
238
|
} = opts.config;
|
|
142
239
|
utooBundlerOpts = {
|
|
143
240
|
...utooBundlerOpts,
|
|
@@ -167,8 +264,13 @@ async function getProdUtooPackConfig(opts) {
|
|
|
167
264
|
},
|
|
168
265
|
sass: opts.config.sassLoader ?? void 0
|
|
169
266
|
},
|
|
267
|
+
// Override process.env for utoopack format
|
|
268
|
+
define: {
|
|
269
|
+
"process.env": JSON.stringify(processEnvForUtoopack)
|
|
270
|
+
},
|
|
170
271
|
nodePolyfill: true,
|
|
171
|
-
externals: getNormalizedExternals(userExternals)
|
|
272
|
+
externals: getNormalizedExternals(userExternals),
|
|
273
|
+
...getSvgModuleRules({ svgr, svgo, inlineLimit })
|
|
172
274
|
},
|
|
173
275
|
opts.config.utoopack || {}
|
|
174
276
|
)
|
|
@@ -201,19 +303,25 @@ async function getDevUtooPackConfig(opts) {
|
|
|
201
303
|
});
|
|
202
304
|
let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
|
|
203
305
|
...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
|
|
204
|
-
|
|
306
|
+
webpackMode: true
|
|
205
307
|
});
|
|
206
308
|
const extraBabelPlugins = [
|
|
207
309
|
...opts.extraBabelPlugins || [],
|
|
208
310
|
...opts.config.extraBabelPlugins || []
|
|
209
311
|
];
|
|
210
312
|
const modularizeImports = getModularizeImports(extraBabelPlugins);
|
|
313
|
+
const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
|
|
211
314
|
const {
|
|
212
315
|
publicPath,
|
|
213
316
|
runtimePublicPath,
|
|
214
317
|
externals: userExternals,
|
|
215
|
-
copy = []
|
|
318
|
+
copy = [],
|
|
319
|
+
svgr,
|
|
320
|
+
svgo = {},
|
|
321
|
+
inlineLimit
|
|
216
322
|
} = opts.config;
|
|
323
|
+
const normalizedExternals = getNormalizedExternals(userExternals);
|
|
324
|
+
debugger;
|
|
217
325
|
utooBundlerOpts = {
|
|
218
326
|
...utooBundlerOpts,
|
|
219
327
|
config: import_utils.lodash.merge(
|
|
@@ -242,8 +350,13 @@ async function getDevUtooPackConfig(opts) {
|
|
|
242
350
|
},
|
|
243
351
|
sass: opts.config.sassLoader ?? void 0
|
|
244
352
|
},
|
|
353
|
+
// Override process.env for utoopack format
|
|
354
|
+
define: {
|
|
355
|
+
"process.env": JSON.stringify(processEnvForUtoopack)
|
|
356
|
+
},
|
|
245
357
|
nodePolyfill: true,
|
|
246
|
-
externals:
|
|
358
|
+
externals: normalizedExternals,
|
|
359
|
+
...getSvgModuleRules({ svgr, svgo, inlineLimit })
|
|
247
360
|
},
|
|
248
361
|
opts.config.utoopack || {}
|
|
249
362
|
),
|
package/dist/index.js
CHANGED
|
@@ -204,7 +204,8 @@ async function dev(opts) {
|
|
|
204
204
|
try {
|
|
205
205
|
await utooPackServe(utooPackConfig, cwd, rootDir, {
|
|
206
206
|
port: utooServePort,
|
|
207
|
-
hostname: "127.0.0.1"
|
|
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.
|
|
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": "1.0
|
|
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.
|
|
18
|
-
"@umijs/bundler-webpack": "4.0.0-canary.
|
|
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"
|