@umijs/bundler-utoopack 4.0.0-canary.20250918.1
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +237 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +234 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +17 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IOpts as IConfigOpts } from '@umijs/bundler-webpack';
|
|
2
|
+
import type { BundleOptions } from '@utoo/pack';
|
|
3
|
+
import type { IOpts } from './types';
|
|
4
|
+
export declare function getProdUtooPackConfig(opts: IOpts): Promise<BundleOptions>;
|
|
5
|
+
export declare type IDevOpts = {
|
|
6
|
+
afterMiddlewares?: any[];
|
|
7
|
+
beforeMiddlewares?: any[];
|
|
8
|
+
onDevCompileDone?: Function;
|
|
9
|
+
onProgress?: Function;
|
|
10
|
+
onMFSUProgress?: Function;
|
|
11
|
+
port?: number;
|
|
12
|
+
host?: string;
|
|
13
|
+
ip?: string;
|
|
14
|
+
babelPreset?: any;
|
|
15
|
+
chainWebpack?: Function;
|
|
16
|
+
modifyWebpackConfig?: Function;
|
|
17
|
+
beforeBabelPlugins?: any[];
|
|
18
|
+
beforeBabelPresets?: any[];
|
|
19
|
+
extraBabelPlugins?: any[];
|
|
20
|
+
extraBabelPresets?: any[];
|
|
21
|
+
cwd: string;
|
|
22
|
+
rootDir: string;
|
|
23
|
+
config: Record<string, any>;
|
|
24
|
+
entry: Record<string, string>;
|
|
25
|
+
mfsuStrategy?: 'eager' | 'normal';
|
|
26
|
+
mfsuInclude?: string[];
|
|
27
|
+
srcCodeCache?: any;
|
|
28
|
+
startBuildWorker?: (deps: any[]) => Worker;
|
|
29
|
+
onBeforeMiddleware?: Function;
|
|
30
|
+
disableCopy?: boolean;
|
|
31
|
+
clean?: boolean;
|
|
32
|
+
} & Pick<IConfigOpts, 'cache' | 'pkg'>;
|
|
33
|
+
export declare function getDevUtooPackConfig(opts: IDevOpts): Promise<BundleOptions>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
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/config.ts
|
|
20
|
+
var config_exports = {};
|
|
21
|
+
__export(config_exports, {
|
|
22
|
+
getDevUtooPackConfig: () => getDevUtooPackConfig,
|
|
23
|
+
getProdUtooPackConfig: () => getProdUtooPackConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
var import_bundler_webpack = require("@umijs/bundler-webpack");
|
|
27
|
+
var import_utils = require("@umijs/utils");
|
|
28
|
+
var import_pack = require("@utoo/pack");
|
|
29
|
+
function convertProcessEnvForUtoopack(webpackConfig) {
|
|
30
|
+
var _a;
|
|
31
|
+
let processEnvForUtoopack = {};
|
|
32
|
+
if (webpackConfig.plugins) {
|
|
33
|
+
const definePlugin = webpackConfig.plugins.find(
|
|
34
|
+
(plugin) => plugin.constructor.name === "DefinePlugin"
|
|
35
|
+
);
|
|
36
|
+
if ((_a = definePlugin == null ? void 0 : definePlugin.definitions) == null ? void 0 : _a["process.env"]) {
|
|
37
|
+
for (const [key, value] of Object.entries(
|
|
38
|
+
definePlugin.definitions["process.env"]
|
|
39
|
+
)) {
|
|
40
|
+
if (typeof value === "string" && value.startsWith('"') && value.endsWith('"')) {
|
|
41
|
+
processEnvForUtoopack[key] = JSON.parse(value);
|
|
42
|
+
} else {
|
|
43
|
+
processEnvForUtoopack[key] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return processEnvForUtoopack;
|
|
49
|
+
}
|
|
50
|
+
function getModularizeImports(extraBabelPlugins) {
|
|
51
|
+
return extraBabelPlugins.filter((p) => /^import$|babel-plugin-import/.test(p[0])).reduce(
|
|
52
|
+
(acc, [_, v]) => {
|
|
53
|
+
const { libraryName, libraryDirectory, style, ...rest } = v;
|
|
54
|
+
if (Object.keys(rest).length > 0) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`babel-plugin-import options ${Object.keys(
|
|
57
|
+
rest
|
|
58
|
+
)} is not supported in utoopack bundler`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (typeof style === "function") {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`babel-plugin-import style function is not supported in utoopack bundler`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
acc[libraryName] = {
|
|
67
|
+
transform: `${libraryName}/${libraryDirectory}/{{ kebabCase member }}`,
|
|
68
|
+
preventFullImport: false,
|
|
69
|
+
skipDefaultConversion: false,
|
|
70
|
+
style: typeof style === "boolean" ? "style" : style
|
|
71
|
+
};
|
|
72
|
+
return acc;
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function getNormalizedAlias(alias, rootDir) {
|
|
78
|
+
const newAlias = { ...alias };
|
|
79
|
+
if (newAlias.react) {
|
|
80
|
+
newAlias["react/*"] = `${newAlias.react}/*`;
|
|
81
|
+
}
|
|
82
|
+
newAlias[`${rootDir}/*`] = `${rootDir}/*`;
|
|
83
|
+
return newAlias;
|
|
84
|
+
}
|
|
85
|
+
async function getProdUtooPackConfig(opts) {
|
|
86
|
+
var _a;
|
|
87
|
+
const webpackConfig = await (0, import_bundler_webpack.getConfig)({
|
|
88
|
+
cwd: opts.cwd,
|
|
89
|
+
rootDir: opts.rootDir,
|
|
90
|
+
env: "production",
|
|
91
|
+
entry: opts.entry,
|
|
92
|
+
userConfig: opts.config,
|
|
93
|
+
analyze: process.env.ANALYZE,
|
|
94
|
+
babelPreset: opts.babelPreset,
|
|
95
|
+
extraBabelPlugins: [
|
|
96
|
+
...opts.beforeBabelPlugins || [],
|
|
97
|
+
...opts.extraBabelPlugins || []
|
|
98
|
+
],
|
|
99
|
+
extraBabelPresets: [
|
|
100
|
+
...opts.beforeBabelPresets || [],
|
|
101
|
+
...opts.extraBabelPresets || []
|
|
102
|
+
],
|
|
103
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
104
|
+
chainWebpack: opts.chainWebpack,
|
|
105
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
106
|
+
pkg: opts.pkg,
|
|
107
|
+
disableCopy: opts.disableCopy
|
|
108
|
+
});
|
|
109
|
+
let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
|
|
110
|
+
...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
|
|
111
|
+
compatMode: true
|
|
112
|
+
});
|
|
113
|
+
const extraBabelPlugins = [
|
|
114
|
+
...opts.extraBabelPlugins || [],
|
|
115
|
+
...opts.config.extraBabelPlugins || []
|
|
116
|
+
];
|
|
117
|
+
const modularizeImports = getModularizeImports(extraBabelPlugins);
|
|
118
|
+
const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
|
|
119
|
+
utooBundlerOpts = {
|
|
120
|
+
...utooBundlerOpts,
|
|
121
|
+
config: {
|
|
122
|
+
...utooBundlerOpts.config,
|
|
123
|
+
output: {
|
|
124
|
+
...utooBundlerOpts.config.output,
|
|
125
|
+
clean: opts.clean
|
|
126
|
+
},
|
|
127
|
+
optimization: {
|
|
128
|
+
...utooBundlerOpts.config.optimization,
|
|
129
|
+
modularizeImports,
|
|
130
|
+
concatenateModules: true
|
|
131
|
+
// minify: false,
|
|
132
|
+
// moduleIds: 'named',
|
|
133
|
+
},
|
|
134
|
+
resolve: {
|
|
135
|
+
...utooBundlerOpts.config.resolve,
|
|
136
|
+
alias: getNormalizedAlias(
|
|
137
|
+
(_a = utooBundlerOpts.config.resolve) == null ? void 0 : _a.alias,
|
|
138
|
+
opts.rootDir
|
|
139
|
+
)
|
|
140
|
+
},
|
|
141
|
+
styles: {
|
|
142
|
+
less: {
|
|
143
|
+
modifyVars: opts.config.theme,
|
|
144
|
+
javascriptEnabled: true,
|
|
145
|
+
...opts.config.lessLoader
|
|
146
|
+
},
|
|
147
|
+
sass: opts.config.sassLoader ?? void 0
|
|
148
|
+
},
|
|
149
|
+
// Override process.env for utoopack format
|
|
150
|
+
define: {
|
|
151
|
+
...utooBundlerOpts.config.define,
|
|
152
|
+
"process.env": JSON.stringify(processEnvForUtoopack)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return utooBundlerOpts;
|
|
157
|
+
}
|
|
158
|
+
async function getDevUtooPackConfig(opts) {
|
|
159
|
+
var _a;
|
|
160
|
+
let webpackConfig = await (0, import_bundler_webpack.getConfig)({
|
|
161
|
+
cwd: opts.cwd,
|
|
162
|
+
rootDir: opts.rootDir,
|
|
163
|
+
env: "development",
|
|
164
|
+
entry: opts.entry,
|
|
165
|
+
userConfig: opts.config,
|
|
166
|
+
babelPreset: opts.babelPreset,
|
|
167
|
+
extraBabelPlugins: [
|
|
168
|
+
...opts.beforeBabelPlugins || [],
|
|
169
|
+
...opts.extraBabelPlugins || []
|
|
170
|
+
],
|
|
171
|
+
extraBabelPresets: [
|
|
172
|
+
...opts.beforeBabelPresets || [],
|
|
173
|
+
...opts.extraBabelPresets || []
|
|
174
|
+
],
|
|
175
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
176
|
+
chainWebpack: opts.chainWebpack,
|
|
177
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
178
|
+
// TO avoild bundler webpack add extra entry.
|
|
179
|
+
hmr: false,
|
|
180
|
+
analyze: process.env.ANALYZE
|
|
181
|
+
});
|
|
182
|
+
let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
|
|
183
|
+
...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
|
|
184
|
+
compatMode: true
|
|
185
|
+
});
|
|
186
|
+
const extraBabelPlugins = [
|
|
187
|
+
...opts.extraBabelPlugins || [],
|
|
188
|
+
...opts.config.extraBabelPlugins || []
|
|
189
|
+
];
|
|
190
|
+
const modularizeImports = getModularizeImports(extraBabelPlugins);
|
|
191
|
+
const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
|
|
192
|
+
utooBundlerOpts = {
|
|
193
|
+
...utooBundlerOpts,
|
|
194
|
+
config: {
|
|
195
|
+
...utooBundlerOpts.config,
|
|
196
|
+
output: {
|
|
197
|
+
...utooBundlerOpts.config.output,
|
|
198
|
+
// utoopack 的 dev 需要默认清空产物目录
|
|
199
|
+
clean: opts.clean === void 0 ? true : opts.clean
|
|
200
|
+
},
|
|
201
|
+
resolve: {
|
|
202
|
+
...utooBundlerOpts.config.resolve,
|
|
203
|
+
alias: getNormalizedAlias(
|
|
204
|
+
(_a = utooBundlerOpts.config.resolve) == null ? void 0 : _a.alias,
|
|
205
|
+
opts.rootDir
|
|
206
|
+
)
|
|
207
|
+
},
|
|
208
|
+
optimization: {
|
|
209
|
+
...utooBundlerOpts.config.optimization,
|
|
210
|
+
modularizeImports
|
|
211
|
+
},
|
|
212
|
+
styles: {
|
|
213
|
+
less: {
|
|
214
|
+
modifyVars: opts.config.theme,
|
|
215
|
+
javascriptEnabled: true,
|
|
216
|
+
...opts.config.lessLoader
|
|
217
|
+
},
|
|
218
|
+
sass: opts.config.sassLoader ?? void 0
|
|
219
|
+
},
|
|
220
|
+
// Override process.env for utoopack format
|
|
221
|
+
define: {
|
|
222
|
+
...utooBundlerOpts.config.define,
|
|
223
|
+
"process.env": JSON.stringify(processEnvForUtoopack)
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
watch: {
|
|
227
|
+
enable: true
|
|
228
|
+
},
|
|
229
|
+
dev: true
|
|
230
|
+
};
|
|
231
|
+
return utooBundlerOpts;
|
|
232
|
+
}
|
|
233
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
234
|
+
0 && (module.exports = {
|
|
235
|
+
getDevUtooPackConfig,
|
|
236
|
+
getProdUtooPackConfig
|
|
237
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
build: () => build,
|
|
34
|
+
dev: () => dev,
|
|
35
|
+
findRootDir: () => import_pack.findRootDir
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
39
|
+
var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
|
|
40
|
+
var import_http_proxy_middleware = require("@umijs/bundler-utils/compiled/http-proxy-middleware");
|
|
41
|
+
var import_utils = require("@umijs/utils");
|
|
42
|
+
var import_fs = __toESM(require("fs"));
|
|
43
|
+
var import_http = __toESM(require("http"));
|
|
44
|
+
var import_path = __toESM(require("path"));
|
|
45
|
+
var import_config = require("./config");
|
|
46
|
+
var import_pack = require("@utoo/pack");
|
|
47
|
+
__reExport(src_exports, require("./config"), module.exports);
|
|
48
|
+
async function build(opts) {
|
|
49
|
+
var _a;
|
|
50
|
+
const { cwd, onBuildComplete } = opts;
|
|
51
|
+
const { build: utooPackBuild, findRootDir: findRootDir2 } = require("@utoo/pack");
|
|
52
|
+
const rootDir = findRootDir2(cwd);
|
|
53
|
+
const utooPackConfig = await (0, import_config.getProdUtooPackConfig)({
|
|
54
|
+
...opts,
|
|
55
|
+
rootDir
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
await utooPackBuild(utooPackConfig, cwd, rootDir);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error(e.message);
|
|
61
|
+
const err = new Error("Build with utoopack failed.");
|
|
62
|
+
err.stack = null;
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
const statsPath = import_path.default.join(
|
|
66
|
+
((_a = utooPackConfig.config.output) == null ? void 0 : _a.path) || "dist",
|
|
67
|
+
"stats.json"
|
|
68
|
+
);
|
|
69
|
+
const stats = JSON.parse(import_fs.default.readFileSync(statsPath, "utf-8"));
|
|
70
|
+
stats.hasErrors = () => false;
|
|
71
|
+
stats.toJson = () => stats;
|
|
72
|
+
stats.toString = () => {
|
|
73
|
+
};
|
|
74
|
+
stats.compilation = {
|
|
75
|
+
...stats,
|
|
76
|
+
assets: stats.assets.reduce(
|
|
77
|
+
(acc, cur) => Object.assign(acc, { [cur.name]: cur }),
|
|
78
|
+
{}
|
|
79
|
+
)
|
|
80
|
+
};
|
|
81
|
+
await (onBuildComplete == null ? void 0 : onBuildComplete({
|
|
82
|
+
stats
|
|
83
|
+
}));
|
|
84
|
+
return stats;
|
|
85
|
+
}
|
|
86
|
+
async function dev(opts) {
|
|
87
|
+
const { cwd, onDevCompileDone } = opts;
|
|
88
|
+
if (!opts) {
|
|
89
|
+
throw new Error("opts should be supplied");
|
|
90
|
+
}
|
|
91
|
+
const { findRootDir: findRootDir2, serve: utooPackServe } = require("@utoo/pack");
|
|
92
|
+
const rootDir = findRootDir2(cwd);
|
|
93
|
+
const utooPackConfig = await (0, import_config.getDevUtooPackConfig)({
|
|
94
|
+
...opts,
|
|
95
|
+
rootDir
|
|
96
|
+
});
|
|
97
|
+
const app = (0, import_express.default)();
|
|
98
|
+
const cors = require("cors");
|
|
99
|
+
const proxy = require("express-http-proxy");
|
|
100
|
+
const port = opts.port || 8e3;
|
|
101
|
+
const utooServePort = port + 1;
|
|
102
|
+
app.use(
|
|
103
|
+
cors({
|
|
104
|
+
origin: true,
|
|
105
|
+
methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
|
|
106
|
+
credentials: true
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
app.use(require("compression")());
|
|
110
|
+
if (opts.onBeforeMiddleware) {
|
|
111
|
+
opts.onBeforeMiddleware(app);
|
|
112
|
+
}
|
|
113
|
+
(opts.beforeMiddlewares || []).forEach((m) => app.use(m));
|
|
114
|
+
const wsProxy = (0, import_http_proxy_middleware.createProxyMiddleware)({
|
|
115
|
+
target: `http://127.0.0.1:${utooServePort}`,
|
|
116
|
+
ws: true,
|
|
117
|
+
logLevel: "silent"
|
|
118
|
+
});
|
|
119
|
+
app.use("/turbopack-hmr", wsProxy);
|
|
120
|
+
if (opts.config.proxy) {
|
|
121
|
+
(0, import_bundler_utils.createProxy)(opts.config.proxy, app);
|
|
122
|
+
}
|
|
123
|
+
app.use(
|
|
124
|
+
proxy(`http://127.0.0.1:${utooServePort}`, {
|
|
125
|
+
proxyReqOptDecorator: function(proxyReqOpts) {
|
|
126
|
+
proxyReqOpts.agent = false;
|
|
127
|
+
return proxyReqOpts;
|
|
128
|
+
},
|
|
129
|
+
filter: function(req, _res) {
|
|
130
|
+
return req.method == "GET" || req.method == "HEAD";
|
|
131
|
+
},
|
|
132
|
+
skipToNextHandlerFilter: function(proxyRes) {
|
|
133
|
+
return proxyRes.statusCode !== 200 && proxyRes.statusCode !== 304;
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
138
|
+
if (m.toString().includes("{ compiler }")) {
|
|
139
|
+
app.use(m({}));
|
|
140
|
+
} else {
|
|
141
|
+
app.use(m);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
app.use(
|
|
145
|
+
require("connect-history-api-fallback")({
|
|
146
|
+
index: "/"
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
let server;
|
|
150
|
+
const httpsOpts = opts.config.https;
|
|
151
|
+
if (httpsOpts) {
|
|
152
|
+
httpsOpts.hosts || (httpsOpts.hosts = import_utils.lodash.uniq(
|
|
153
|
+
[
|
|
154
|
+
...httpsOpts.hosts || [],
|
|
155
|
+
// always add localhost, 127.0.0.1, ip and host
|
|
156
|
+
"127.0.0.1",
|
|
157
|
+
"localhost",
|
|
158
|
+
opts.ip,
|
|
159
|
+
opts.host !== "0.0.0.0" && opts.host
|
|
160
|
+
].filter(Boolean)
|
|
161
|
+
));
|
|
162
|
+
server = await (0, import_bundler_utils.createHttpsServer)(app, httpsOpts);
|
|
163
|
+
} else {
|
|
164
|
+
server = import_http.default.createServer(app);
|
|
165
|
+
}
|
|
166
|
+
server.listen(port, () => {
|
|
167
|
+
const protocol = opts.config.https ? "https:" : "http:";
|
|
168
|
+
const banner = getDevBanner(
|
|
169
|
+
protocol,
|
|
170
|
+
opts.host,
|
|
171
|
+
port,
|
|
172
|
+
opts.ip ?? "0.0.0.0"
|
|
173
|
+
);
|
|
174
|
+
console.log(banner);
|
|
175
|
+
});
|
|
176
|
+
if (wsProxy.upgrade) {
|
|
177
|
+
server.on("upgrade", wsProxy.upgrade);
|
|
178
|
+
}
|
|
179
|
+
const createStatsObject = () => {
|
|
180
|
+
var _a;
|
|
181
|
+
let stats;
|
|
182
|
+
try {
|
|
183
|
+
const statsPath = import_path.default.join(
|
|
184
|
+
((_a = utooPackConfig.config.output) == null ? void 0 : _a.path) || "dist",
|
|
185
|
+
"stats.json"
|
|
186
|
+
);
|
|
187
|
+
stats = JSON.parse(import_fs.default.readFileSync(statsPath, "utf-8"));
|
|
188
|
+
} catch (e) {
|
|
189
|
+
throw new Error("Stats.json not found by utoopack dev");
|
|
190
|
+
}
|
|
191
|
+
stats.hasErrors = () => false;
|
|
192
|
+
stats.toJson = () => stats;
|
|
193
|
+
stats.toString = () => {
|
|
194
|
+
};
|
|
195
|
+
stats.compilation = {
|
|
196
|
+
...stats,
|
|
197
|
+
assets: stats.assets.reduce(
|
|
198
|
+
(acc, cur) => Object.assign(acc, { [cur.name]: cur }),
|
|
199
|
+
{}
|
|
200
|
+
)
|
|
201
|
+
};
|
|
202
|
+
return stats;
|
|
203
|
+
};
|
|
204
|
+
try {
|
|
205
|
+
await utooPackServe(utooPackConfig, cwd, rootDir, {
|
|
206
|
+
port: utooServePort,
|
|
207
|
+
hostname: opts.host
|
|
208
|
+
});
|
|
209
|
+
const stats = createStatsObject();
|
|
210
|
+
await (onDevCompileDone == null ? void 0 : onDevCompileDone({
|
|
211
|
+
stats
|
|
212
|
+
}));
|
|
213
|
+
return stats;
|
|
214
|
+
} catch (e) {
|
|
215
|
+
console.error(e.message);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function getDevBanner(protocol, host, port, ip) {
|
|
219
|
+
const hostStr = host === "0.0.0.0" ? "localhost" : host;
|
|
220
|
+
const messages = [];
|
|
221
|
+
messages.push(" App listening at:");
|
|
222
|
+
messages.push(
|
|
223
|
+
` - Local: ${import_utils.chalk.cyan(`${protocol}//${hostStr}:${port}`)}`
|
|
224
|
+
);
|
|
225
|
+
messages.push(` - Network: ${import_utils.chalk.cyan(`${protocol}//${ip}:${port}`)}`);
|
|
226
|
+
return messages.join("\n");
|
|
227
|
+
}
|
|
228
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
build,
|
|
231
|
+
dev,
|
|
232
|
+
findRootDir,
|
|
233
|
+
...require("./config")
|
|
234
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IOpts as IConfigOpts } from '@umijs/bundler-webpack';
|
|
2
|
+
export declare type IOpts = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
entry: Record<string, string>;
|
|
6
|
+
config: Record<string, any>;
|
|
7
|
+
onBuildComplete?: Function;
|
|
8
|
+
babelPreset?: any;
|
|
9
|
+
chainWebpack?: Function;
|
|
10
|
+
modifyWebpackConfig?: Function;
|
|
11
|
+
beforeBabelPlugins?: any[];
|
|
12
|
+
beforeBabelPresets?: any[];
|
|
13
|
+
extraBabelPlugins?: any[];
|
|
14
|
+
extraBabelPresets?: any[];
|
|
15
|
+
clean?: boolean;
|
|
16
|
+
watch?: boolean;
|
|
17
|
+
disableCopy?: boolean;
|
|
18
|
+
} & Pick<IConfigOpts, 'cache' | 'pkg'>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umijs/bundler-utoopack",
|
|
3
|
+
"version": "4.0.0-canary.20250918.1",
|
|
4
|
+
"description": "@umijs/bundler-utoopack",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"compression": "^1.7.4",
|
|
12
|
+
"connect-history-api-fallback": "^2.0.0",
|
|
13
|
+
"cors": "^2.8.5",
|
|
14
|
+
"express": "^4.18.2",
|
|
15
|
+
"express-http-proxy": "^2.1.1",
|
|
16
|
+
"@umijs/bundler-utils": "4.0.0-canary.20250918.1",
|
|
17
|
+
"@umijs/bundler-webpack": "4.0.0-canary.20250918.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@utoo/pack": "0.0.1-alpha.47",
|
|
21
|
+
"father": "4.1.5"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@utoo/pack": "^0.0.1-alpha.47"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "father build",
|
|
31
|
+
"dev": "father dev"
|
|
32
|
+
}
|
|
33
|
+
}
|