@modern-js/app-tools 2.13.4 → 2.15.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/CHANGELOG.md +101 -0
- package/dist/cjs/analyze/constants.js +3 -1
- package/dist/cjs/analyze/getServerRoutes.js +5 -2
- package/dist/cjs/analyze/nestedRoutes.js +12 -0
- package/dist/cjs/analyze/templates.js +18 -1
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +136 -0
- package/dist/cjs/builder/builder-rspack/index.js +6 -1
- package/dist/cjs/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +9 -10
- package/dist/cjs/builder/builder-webpack/createCopyPattern.js +67 -0
- package/dist/cjs/builder/builder-webpack/index.js +4 -4
- package/dist/cjs/builder/shared/{createCopyPattern.js → createCopyInfo.js} +11 -44
- package/dist/cjs/builder/shared/index.js +1 -1
- package/dist/cjs/config/default.js +3 -1
- package/dist/cjs/config/initialize/inits.js +0 -7
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/locale/en.js +5 -5
- package/dist/cjs/locale/zh.js +4 -4
- package/dist/cjs/schema/legacy.js +1 -1
- package/dist/esm/analyze/constants.js +3 -1
- package/dist/esm/analyze/getServerRoutes.js +4 -2
- package/dist/esm/analyze/nestedRoutes.js +13 -1
- package/dist/esm/analyze/templates.js +35 -3
- package/dist/esm/builder/builder-rspack/adapterCopy.js +372 -0
- package/dist/esm/builder/builder-rspack/index.js +8 -1
- package/dist/esm/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -5
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +39 -0
- package/dist/esm/builder/builder-webpack/index.js +4 -4
- package/dist/esm/builder/shared/createCopyInfo.js +12 -0
- package/dist/esm/builder/shared/index.js +1 -1
- package/dist/esm/config/default.js +3 -1
- package/dist/esm/config/initialize/inits.js +0 -7
- package/dist/esm/index.js +7 -2
- package/dist/esm/locale/en.js +5 -5
- package/dist/esm/locale/zh.js +4 -4
- package/dist/esm/schema/legacy.js +4 -1
- package/dist/esm-node/analyze/constants.js +3 -1
- package/dist/esm-node/analyze/getServerRoutes.js +5 -2
- package/dist/esm-node/analyze/nestedRoutes.js +12 -0
- package/dist/esm-node/analyze/templates.js +18 -1
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +103 -0
- package/dist/esm-node/builder/builder-rspack/index.js +6 -1
- package/dist/esm-node/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -6
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +43 -0
- package/dist/esm-node/builder/builder-webpack/index.js +4 -4
- package/dist/esm-node/builder/shared/createCopyInfo.js +17 -0
- package/dist/esm-node/builder/shared/index.js +1 -1
- package/dist/esm-node/config/default.js +3 -1
- package/dist/esm-node/config/initialize/inits.js +0 -7
- package/dist/esm-node/index.js +6 -3
- package/dist/esm-node/locale/en.js +5 -5
- package/dist/esm-node/locale/zh.js +4 -4
- package/dist/esm-node/schema/legacy.js +1 -1
- package/dist/types/analyze/constants.d.ts +2 -0
- package/dist/types/builder/builder-rspack/adapterCopy.d.ts +4 -0
- package/dist/types/builder/builder-webpack/{builderPlugins/compatModern.d.ts → adapterModern.d.ts} +2 -2
- package/dist/types/builder/{shared → builder-webpack}/createCopyPattern.d.ts +3 -3
- package/dist/types/builder/shared/createCopyInfo.d.ts +6 -0
- package/dist/types/builder/shared/index.d.ts +2 -2
- package/dist/types/types/config/deploy.d.ts +3 -0
- package/lib/types.d.ts +1 -0
- package/package.json +24 -24
- package/dist/esm/builder/shared/createCopyPattern.js +0 -44
- package/dist/esm-node/builder/shared/createCopyPattern.js +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.15.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 18aeb8c: fix(app-tools): missing MODERN_TARGET type
|
|
8
|
+
|
|
9
|
+
fix(app-tools): 缺少 MODERN_TARGET 类型定义
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7d23d39]
|
|
12
|
+
- Updated dependencies [3e5e790]
|
|
13
|
+
- @modern-js/builder-rspack-provider@2.15.0
|
|
14
|
+
- @modern-js/builder-webpack-provider@2.15.0
|
|
15
|
+
- @modern-js/builder-shared@2.15.0
|
|
16
|
+
- @modern-js/builder@2.15.0
|
|
17
|
+
- @modern-js/builder-plugin-esbuild@2.15.0
|
|
18
|
+
- @modern-js/builder-plugin-node-polyfill@2.15.0
|
|
19
|
+
- @modern-js/core@2.15.0
|
|
20
|
+
- @modern-js/plugin-data-loader@2.15.0
|
|
21
|
+
- @modern-js/plugin-i18n@2.15.0
|
|
22
|
+
- @modern-js/plugin-lint@2.15.0
|
|
23
|
+
- @modern-js/new-action@2.15.0
|
|
24
|
+
- @modern-js/prod-server@2.15.0
|
|
25
|
+
- @modern-js/server@2.15.0
|
|
26
|
+
- @modern-js/node-bundle-require@2.15.0
|
|
27
|
+
- @modern-js/plugin@2.15.0
|
|
28
|
+
- @modern-js/types@2.15.0
|
|
29
|
+
- @modern-js/upgrade@2.15.0
|
|
30
|
+
- @modern-js/utils@2.15.0
|
|
31
|
+
|
|
32
|
+
## 2.14.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 7c5c752: feat: adpate rspack copy plugin
|
|
37
|
+
feat: 适配 rspack copy 插件
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- b7b181e: fix(app-tools): failed to scan public dir when using Rspack
|
|
42
|
+
|
|
43
|
+
fix(app-tools): 修复 Rspack 模式读取 public 目录失败的问题
|
|
44
|
+
|
|
45
|
+
- b7f72a6: fix(app-tools): can not disable output.cleanDistPath
|
|
46
|
+
|
|
47
|
+
fix(app-tools): 修复无法禁用 output.cleanDistPath 的问题
|
|
48
|
+
|
|
49
|
+
- 9321bef: feat: adjust server.worker config to deploy.worker.ssr
|
|
50
|
+
|
|
51
|
+
feat: 调整 server.worker 为 deploy.worker.ssr
|
|
52
|
+
|
|
53
|
+
- d102ba3: fix(app-tools): failed to validate globalVars in legacy mode
|
|
54
|
+
|
|
55
|
+
fix(app-tools): 修复兼容模式下 globalVars 类型校验错误的问题
|
|
56
|
+
|
|
57
|
+
- 52d0cb1: feat: support config handle of Route
|
|
58
|
+
feat: 支持配置 Route 的 handle 属性
|
|
59
|
+
- 432ac8b: chore(cli): improve commands descriptions
|
|
60
|
+
|
|
61
|
+
chore(cli): 优化命令的描述文案
|
|
62
|
+
|
|
63
|
+
- 864d55e: feat(builder): source.globalVars support function usage
|
|
64
|
+
|
|
65
|
+
feat(builder): source.globalVars 支持函数写法
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [b46fbcb]
|
|
68
|
+
- Updated dependencies [4779152]
|
|
69
|
+
- Updated dependencies [bd52693]
|
|
70
|
+
- Updated dependencies [fefd1c5]
|
|
71
|
+
- Updated dependencies [8a3c693]
|
|
72
|
+
- Updated dependencies [9321bef]
|
|
73
|
+
- Updated dependencies [4baf588]
|
|
74
|
+
- Updated dependencies [d0efae3]
|
|
75
|
+
- Updated dependencies [9b45c58]
|
|
76
|
+
- Updated dependencies [1f34dba]
|
|
77
|
+
- Updated dependencies [52d0cb1]
|
|
78
|
+
- Updated dependencies [60a81d0]
|
|
79
|
+
- Updated dependencies [432ac8b]
|
|
80
|
+
- Updated dependencies [864d55e]
|
|
81
|
+
- Updated dependencies [b965df2]
|
|
82
|
+
- Updated dependencies [dacef96]
|
|
83
|
+
- Updated dependencies [d05651a]
|
|
84
|
+
- Updated dependencies [16399fd]
|
|
85
|
+
- @modern-js/builder-shared@2.14.0
|
|
86
|
+
- @modern-js/server@2.14.0
|
|
87
|
+
- @modern-js/utils@2.14.0
|
|
88
|
+
- @modern-js/builder-webpack-provider@2.14.0
|
|
89
|
+
- @modern-js/builder-rspack-provider@2.14.0
|
|
90
|
+
- @modern-js/types@2.14.0
|
|
91
|
+
- @modern-js/prod-server@2.14.0
|
|
92
|
+
- @modern-js/plugin-lint@2.14.0
|
|
93
|
+
- @modern-js/plugin-data-loader@2.14.0
|
|
94
|
+
- @modern-js/builder@2.14.0
|
|
95
|
+
- @modern-js/builder-plugin-esbuild@2.14.0
|
|
96
|
+
- @modern-js/builder-plugin-node-polyfill@2.14.0
|
|
97
|
+
- @modern-js/core@2.14.0
|
|
98
|
+
- @modern-js/plugin-i18n@2.14.0
|
|
99
|
+
- @modern-js/new-action@2.14.0
|
|
100
|
+
- @modern-js/node-bundle-require@2.14.0
|
|
101
|
+
- @modern-js/upgrade@2.14.0
|
|
102
|
+
- @modern-js/plugin@2.14.0
|
|
103
|
+
|
|
3
104
|
## 2.13.4
|
|
4
105
|
|
|
5
106
|
### Patch Changes
|
|
@@ -68,7 +68,9 @@ const NESTED_ROUTE = {
|
|
|
68
68
|
ERROR_FILE: "error",
|
|
69
69
|
LOADER_FILE: "loader",
|
|
70
70
|
SPLATE_FILE: "$",
|
|
71
|
-
SPLATE_LOADER_FILE: "$.loader"
|
|
71
|
+
SPLATE_LOADER_FILE: "$.loader",
|
|
72
|
+
LAYOUT_CONFIG_FILE: "layout.config",
|
|
73
|
+
PAGE_CONFIG_FILE: "page.config"
|
|
72
74
|
};
|
|
73
75
|
const APP_CONFIG_NAME = "config";
|
|
74
76
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -98,12 +98,15 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
98
98
|
return routes;
|
|
99
99
|
};
|
|
100
100
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
101
|
+
var _a;
|
|
101
102
|
const {
|
|
102
103
|
html: { disableHtmlFolder },
|
|
103
104
|
output: { distPath: { html: htmlPath } = {} },
|
|
104
|
-
server: { baseUrl, routes, ssr, ssrByEntries
|
|
105
|
+
server: { baseUrl, routes, ssr, ssrByEntries },
|
|
106
|
+
deploy
|
|
105
107
|
} = config;
|
|
106
108
|
const { packageName } = appContext;
|
|
109
|
+
const workerSSR = (_a = deploy == null ? void 0 : deploy.worker) == null ? void 0 : _a.ssr;
|
|
107
110
|
let htmlRoutes = entrypoints.reduce(
|
|
108
111
|
(previous, { entryName }) => {
|
|
109
112
|
const entryOptions = (0, import_utils.getEntryOptions)(
|
|
@@ -113,7 +116,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
113
116
|
packageName
|
|
114
117
|
);
|
|
115
118
|
const isSSR = Boolean(entryOptions);
|
|
116
|
-
const isWorker = Boolean(
|
|
119
|
+
const isWorker = Boolean(workerSSR);
|
|
117
120
|
const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
|
|
118
121
|
let route = {
|
|
119
122
|
urlPath: `/${entryName === import_utils.MAIN_ENTRY_NAME ? "" : entryName}`,
|
|
@@ -87,6 +87,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
87
87
|
let pageRoute = null;
|
|
88
88
|
let splatLoaderFile = "";
|
|
89
89
|
let splatRoute = null;
|
|
90
|
+
let pageConfigFile = "";
|
|
90
91
|
const items = await import_utils.fs.readdir(dirname);
|
|
91
92
|
for (const item of items) {
|
|
92
93
|
const itemPath = path.join(dirname, item);
|
|
@@ -107,12 +108,20 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
107
108
|
route.loader = itemPath;
|
|
108
109
|
}
|
|
109
110
|
}
|
|
111
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
|
|
112
|
+
if (!route.config) {
|
|
113
|
+
route.config = itemPath;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
110
116
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_FILE) {
|
|
111
117
|
route._component = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
112
118
|
}
|
|
113
119
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
114
120
|
pageLoaderFile = itemPath;
|
|
115
121
|
}
|
|
122
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_CONFIG_FILE) {
|
|
123
|
+
pageConfigFile = itemPath;
|
|
124
|
+
}
|
|
116
125
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_FILE) {
|
|
117
126
|
pageRoute = createIndexRoute(
|
|
118
127
|
{
|
|
@@ -125,6 +134,9 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
125
134
|
if (pageLoaderFile) {
|
|
126
135
|
pageRoute.loader = pageLoaderFile;
|
|
127
136
|
}
|
|
137
|
+
if (pageConfigFile) {
|
|
138
|
+
pageRoute.config = pageConfigFile;
|
|
139
|
+
}
|
|
128
140
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
129
141
|
}
|
|
130
142
|
if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
@@ -187,6 +187,8 @@ const fileSystemRoutes = async ({
|
|
|
187
187
|
const errors = [];
|
|
188
188
|
const loaders = [];
|
|
189
189
|
const loadersMap = {};
|
|
190
|
+
const configs = [];
|
|
191
|
+
const configsMap = {};
|
|
190
192
|
const loadersMapFile = import_path.default.join(
|
|
191
193
|
internalDirectory,
|
|
192
194
|
entryName,
|
|
@@ -216,6 +218,7 @@ const fileSystemRoutes = async ({
|
|
|
216
218
|
let loading;
|
|
217
219
|
let error;
|
|
218
220
|
let loader;
|
|
221
|
+
let config;
|
|
219
222
|
let component = "";
|
|
220
223
|
let lazyImport = null;
|
|
221
224
|
if (route.type === "nested") {
|
|
@@ -237,6 +240,12 @@ const fileSystemRoutes = async ({
|
|
|
237
240
|
inline: false
|
|
238
241
|
};
|
|
239
242
|
}
|
|
243
|
+
if (typeof route.config === "string") {
|
|
244
|
+
configs.push(route.config);
|
|
245
|
+
const configId = configs.length - 1;
|
|
246
|
+
config = `config_${configId}`;
|
|
247
|
+
configsMap[config] = route.config;
|
|
248
|
+
}
|
|
240
249
|
if (route._component) {
|
|
241
250
|
if (splitRouteChunks) {
|
|
242
251
|
if (route.isRoot) {
|
|
@@ -268,6 +277,7 @@ const fileSystemRoutes = async ({
|
|
|
268
277
|
lazyImport,
|
|
269
278
|
loading,
|
|
270
279
|
loader,
|
|
280
|
+
config,
|
|
271
281
|
error,
|
|
272
282
|
children
|
|
273
283
|
};
|
|
@@ -288,7 +298,8 @@ const fileSystemRoutes = async ({
|
|
|
288
298
|
"lazyImport",
|
|
289
299
|
"loader",
|
|
290
300
|
"loading",
|
|
291
|
-
"error"
|
|
301
|
+
"error",
|
|
302
|
+
"config"
|
|
292
303
|
];
|
|
293
304
|
const regs = keywords.map(createMatchReg);
|
|
294
305
|
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
|
|
@@ -334,6 +345,11 @@ const fileSystemRoutes = async ({
|
|
|
334
345
|
`;
|
|
335
346
|
}
|
|
336
347
|
}
|
|
348
|
+
let importConfigsCode = "";
|
|
349
|
+
for (const [key, configPath] of Object.entries(configsMap)) {
|
|
350
|
+
importConfigsCode += `import * as ${key} from "${(0, import_utils.slash)(configPath)}";
|
|
351
|
+
`;
|
|
352
|
+
}
|
|
337
353
|
await import_utils.fs.ensureFile(loadersMapFile);
|
|
338
354
|
await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
339
355
|
return `
|
|
@@ -343,6 +359,7 @@ const fileSystemRoutes = async ({
|
|
|
343
359
|
${importLoadingCode}
|
|
344
360
|
${importErrorComponentsCode}
|
|
345
361
|
${importLoadersCode}
|
|
362
|
+
${importConfigsCode}
|
|
346
363
|
${routeComponentsCode}
|
|
347
364
|
`;
|
|
348
365
|
};
|
|
@@ -0,0 +1,136 @@
|
|
|
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 __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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var adapterCopy_exports = {};
|
|
29
|
+
__export(adapterCopy_exports, {
|
|
30
|
+
builderPluginAdpaterCopy: () => builderPluginAdpaterCopy
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(adapterCopy_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_shared = require("../shared");
|
|
37
|
+
const builderPluginAdpaterCopy = (options) => ({
|
|
38
|
+
name: "builder-plugin-adapter-rspack-copy",
|
|
39
|
+
setup(api) {
|
|
40
|
+
let publicPath;
|
|
41
|
+
api.modifyRspackConfig((config) => {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
config.builtins = {
|
|
44
|
+
...config.builtins || {},
|
|
45
|
+
copy: {
|
|
46
|
+
patterns: [
|
|
47
|
+
...transformCopy((_b = (_a = config.builtins) == null ? void 0 : _a.copy) == null ? void 0 : _b.patterns),
|
|
48
|
+
...createConfigBuiltinCopy(options)
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
publicPath = (_c = config.output) == null ? void 0 : _c.publicPath;
|
|
53
|
+
});
|
|
54
|
+
api.onDevCompileDone(async () => {
|
|
55
|
+
await transformHtmlFiles();
|
|
56
|
+
});
|
|
57
|
+
api.onAfterBuild(async () => {
|
|
58
|
+
await transformHtmlFiles();
|
|
59
|
+
});
|
|
60
|
+
async function transformHtmlFiles() {
|
|
61
|
+
var _a;
|
|
62
|
+
const { normalizedConfig } = options;
|
|
63
|
+
const publicDir = import_path.default.resolve(
|
|
64
|
+
((_a = normalizedConfig.output.distPath) == null ? void 0 : _a.root) || "./dist",
|
|
65
|
+
"./public"
|
|
66
|
+
);
|
|
67
|
+
if (!import_fs_extra.default.existsSync(publicDir) || !import_fs_extra.default.statSync(publicDir).isDirectory()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const HTML_REGEXP = /\.html?$/;
|
|
71
|
+
const filepaths = (await import_fs_extra.default.readdir(publicDir)).map(
|
|
72
|
+
(file) => import_path.default.resolve(publicDir, file)
|
|
73
|
+
);
|
|
74
|
+
await Promise.all(
|
|
75
|
+
filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
|
76
|
+
const content = await import_fs_extra.default.readFile(file, "utf-8");
|
|
77
|
+
if (publicPath) {
|
|
78
|
+
await import_fs_extra.default.writeFile(
|
|
79
|
+
file,
|
|
80
|
+
content.replace(
|
|
81
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
82
|
+
(0, import_utils.removeTailSlash)(publicPath)
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
import_utils.logger.warn(
|
|
87
|
+
"Expect get a string from `publicPath`, but receive `undefined`."
|
|
88
|
+
);
|
|
89
|
+
await import_fs_extra.default.writeFile(
|
|
90
|
+
file,
|
|
91
|
+
content.replace(
|
|
92
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
93
|
+
(0, import_utils.removeTailSlash)("/")
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
function transformCopy(patterns) {
|
|
103
|
+
if (patterns) {
|
|
104
|
+
patterns.map((value) => {
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
return {
|
|
107
|
+
from: value
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
function createConfigBuiltinCopy(options) {
|
|
116
|
+
const { normalizedConfig, appContext } = options;
|
|
117
|
+
const { uploadDir, publicDir } = (0, import_shared.createCopyInfo)(appContext, normalizedConfig);
|
|
118
|
+
return [
|
|
119
|
+
{
|
|
120
|
+
from: "**/*",
|
|
121
|
+
to: "public",
|
|
122
|
+
context: publicDir,
|
|
123
|
+
noErrorOnMissing: true
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
from: "**/*",
|
|
127
|
+
to: "upload",
|
|
128
|
+
context: uploadDir,
|
|
129
|
+
noErrorOnMissing: true
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
builderPluginAdpaterCopy
|
|
136
|
+
});
|
|
@@ -22,8 +22,13 @@ __export(builder_rspack_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(builder_rspack_exports);
|
|
23
23
|
var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
|
|
24
24
|
var import_generator = require("../generator");
|
|
25
|
+
var import_adapterCopy = require("./adapterCopy");
|
|
25
26
|
function createRspackBuilderForModern(options) {
|
|
26
|
-
return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider
|
|
27
|
+
return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider, {
|
|
28
|
+
modifyBuilderInstance(builder) {
|
|
29
|
+
builder.addPlugins([(0, import_adapterCopy.builderPluginAdpaterCopy)(options)]);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
27
32
|
}
|
|
28
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
34
|
0 && (module.exports = {
|
package/dist/cjs/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js}
RENAMED
|
@@ -15,24 +15,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
-
|
|
18
|
+
var adapterModern_exports = {};
|
|
19
|
+
__export(adapterModern_exports, {
|
|
20
|
+
builderPluginAdapterModern: () => builderPluginAdapterModern
|
|
21
21
|
});
|
|
22
|
-
module.exports = __toCommonJS(
|
|
22
|
+
module.exports = __toCommonJS(adapterModern_exports);
|
|
23
23
|
var import_path = require("path");
|
|
24
|
-
var
|
|
25
|
-
const
|
|
26
|
-
name: "builder-plugin-
|
|
24
|
+
var import_createCopyPattern = require("./createCopyPattern");
|
|
25
|
+
const builderPluginAdapterModern = (options) => ({
|
|
26
|
+
name: "builder-plugin-adapter-",
|
|
27
27
|
setup(api) {
|
|
28
28
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
29
29
|
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
30
30
|
chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
|
|
31
31
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
32
|
-
const defaultCopyPattern = (0,
|
|
32
|
+
const defaultCopyPattern = (0, import_createCopyPattern.createPublicPattern)(
|
|
33
33
|
appContext,
|
|
34
34
|
modernConfig,
|
|
35
|
-
"public",
|
|
36
35
|
chain
|
|
37
36
|
);
|
|
38
37
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
@@ -49,5 +48,5 @@ const builderPluginCompatModern = (options) => ({
|
|
|
49
48
|
});
|
|
50
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
50
|
0 && (module.exports = {
|
|
52
|
-
|
|
51
|
+
builderPluginAdapterModern
|
|
53
52
|
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
var createCopyPattern_exports = {};
|
|
19
|
+
__export(createCopyPattern_exports, {
|
|
20
|
+
createPublicPattern: () => createPublicPattern,
|
|
21
|
+
createUploadPattern: () => createUploadPattern
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createCopyPattern_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import_shared = require("../shared");
|
|
26
|
+
const minifiedJsRexExp = /\.min\.js/;
|
|
27
|
+
const info = (file) => ({
|
|
28
|
+
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
29
|
+
// So we don't want copy-webpack-plugin to minify it.
|
|
30
|
+
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
31
|
+
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
32
|
+
});
|
|
33
|
+
function createPublicPattern(appContext, config, chain) {
|
|
34
|
+
const { publicDir } = (0, import_shared.createCopyInfo)(appContext, config);
|
|
35
|
+
return {
|
|
36
|
+
info,
|
|
37
|
+
from: "**/*",
|
|
38
|
+
to: "public",
|
|
39
|
+
context: publicDir,
|
|
40
|
+
noErrorOnMissing: true,
|
|
41
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
42
|
+
transform: (content, absoluteFrom) => {
|
|
43
|
+
if (!/\.html?$/.test(absoluteFrom)) {
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
return content.toString("utf8").replace(
|
|
47
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
48
|
+
(0, import_utils.removeTailSlash)(chain.output.get("publicPath"))
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createUploadPattern(appContext, config) {
|
|
54
|
+
const { uploadDir } = (0, import_shared.createCopyInfo)(appContext, config);
|
|
55
|
+
return {
|
|
56
|
+
info,
|
|
57
|
+
from: "**/*",
|
|
58
|
+
to: "upload",
|
|
59
|
+
context: uploadDir,
|
|
60
|
+
noErrorOnMissing: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
createPublicPattern,
|
|
66
|
+
createUploadPattern
|
|
67
|
+
});
|
|
@@ -31,9 +31,9 @@ __export(builder_webpack_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(builder_webpack_exports);
|
|
33
33
|
var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
|
|
34
|
-
var import_shared = require("../shared");
|
|
35
34
|
var import_generator = require("../generator");
|
|
36
|
-
var
|
|
35
|
+
var import_adapterModern = require("./adapterModern");
|
|
36
|
+
var import_createCopyPattern = require("./createCopyPattern");
|
|
37
37
|
function createWebpackBuilderForModern(options) {
|
|
38
38
|
return (0, import_generator.generateBuilder)(options, import_builder_webpack_provider.builderWebpackProvider, {
|
|
39
39
|
modifyBuilderConfig(config) {
|
|
@@ -47,7 +47,7 @@ function createWebpackBuilderForModern(options) {
|
|
|
47
47
|
function modifyOutputConfig(config, appContext) {
|
|
48
48
|
config.output = createOutputConfig(config, appContext);
|
|
49
49
|
function createOutputConfig(config2, appContext2) {
|
|
50
|
-
const defaultCopyPattern = (0,
|
|
50
|
+
const defaultCopyPattern = (0, import_createCopyPattern.createUploadPattern)(appContext2, config2);
|
|
51
51
|
const { copy } = config2.output;
|
|
52
52
|
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
53
53
|
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
@@ -64,7 +64,7 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
64
64
|
const { builderPluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
|
|
65
65
|
builder.addPlugins([builderPluginEsbuild(esbuildOptions)]);
|
|
66
66
|
}
|
|
67
|
-
builder.addPlugins([(0,
|
|
67
|
+
builder.addPlugins([(0, import_adapterModern.builderPluginAdapterModern)(options)]);
|
|
68
68
|
}
|
|
69
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
70
|
0 && (module.exports = {
|
|
@@ -25,59 +25,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
30
|
-
|
|
28
|
+
var createCopyInfo_exports = {};
|
|
29
|
+
__export(createCopyInfo_exports, {
|
|
30
|
+
createCopyInfo: () => createCopyInfo
|
|
31
31
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(createCopyInfo_exports);
|
|
33
33
|
var import_path = __toESM(require("path"));
|
|
34
|
-
|
|
35
|
-
function createCopyPattern(appContext, config, patternsType, chain) {
|
|
34
|
+
function createCopyInfo(appContext, config) {
|
|
36
35
|
const configDir = import_path.default.resolve(
|
|
37
36
|
appContext.appDirectory,
|
|
38
37
|
config.source.configDir || "./config"
|
|
39
38
|
);
|
|
40
39
|
const uploadDir = import_path.default.posix.join(configDir.replace(/\\/g, "/"), "upload");
|
|
41
40
|
const publicDir = import_path.default.posix.join(configDir.replace(/\\/g, "/"), "public");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
48
|
-
});
|
|
49
|
-
if (patternsType === "public") {
|
|
50
|
-
if (!chain) {
|
|
51
|
-
throw new Error("expect get a webpackChain, but receive 'undefined'");
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
info,
|
|
55
|
-
from: "**/*",
|
|
56
|
-
to: "public",
|
|
57
|
-
context: publicDir,
|
|
58
|
-
noErrorOnMissing: true,
|
|
59
|
-
// eslint-disable-next-line node/prefer-global/buffer
|
|
60
|
-
transform: (content, absoluteFrom) => {
|
|
61
|
-
if (!/\.html?$/.test(absoluteFrom)) {
|
|
62
|
-
return content;
|
|
63
|
-
}
|
|
64
|
-
return content.toString("utf8").replace(
|
|
65
|
-
/<%=\s*assetPrefix\s*%>/g,
|
|
66
|
-
(0, import_utils.removeTailSlash)(chain.output.get("publicPath"))
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
} else {
|
|
71
|
-
return {
|
|
72
|
-
info,
|
|
73
|
-
from: "**/*",
|
|
74
|
-
to: "upload",
|
|
75
|
-
context: uploadDir,
|
|
76
|
-
noErrorOnMissing: true
|
|
77
|
-
};
|
|
78
|
-
}
|
|
41
|
+
return {
|
|
42
|
+
configDir,
|
|
43
|
+
uploadDir,
|
|
44
|
+
publicDir
|
|
45
|
+
};
|
|
79
46
|
}
|
|
80
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
48
|
0 && (module.exports = {
|
|
82
|
-
|
|
49
|
+
createCopyInfo
|
|
83
50
|
});
|
|
@@ -14,6 +14,6 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
15
|
var shared_exports = {};
|
|
16
16
|
module.exports = __toCommonJS(shared_exports);
|
|
17
|
-
__reExport(shared_exports, require("./createCopyPattern"), module.exports);
|
|
18
17
|
__reExport(shared_exports, require("./types"), module.exports);
|
|
19
18
|
__reExport(shared_exports, require("./builderPlugins"), module.exports);
|
|
19
|
+
__reExport(shared_exports, require("./createCopyInfo"), module.exports);
|
|
@@ -22,6 +22,7 @@ __export(default_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(default_exports);
|
|
24
24
|
var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
|
|
25
|
+
var import_env = require("../utils/env");
|
|
25
26
|
function createDefaultConfig(appContext, bundler) {
|
|
26
27
|
const defaultBuilderConfig = (0, import_builder_webpack_provider.createDefaultConfig)();
|
|
27
28
|
const dev = {
|
|
@@ -41,6 +42,7 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
41
42
|
disableDefaultEntries: false,
|
|
42
43
|
entriesDir: "./src",
|
|
43
44
|
configDir: "./config",
|
|
45
|
+
globalVars: (0, import_env.getAutoInjectEnv)(appContext),
|
|
44
46
|
alias: {
|
|
45
47
|
[appContext.internalDirAlias]: appContext.internalDirectory,
|
|
46
48
|
[appContext.internalSrcAlias]: appContext.srcDirectory,
|
|
@@ -101,7 +103,7 @@ function createLegacyDefaultConfig(appContext) {
|
|
|
101
103
|
configDir: "./config",
|
|
102
104
|
apiDir: "./api",
|
|
103
105
|
envVars: [],
|
|
104
|
-
globalVars:
|
|
106
|
+
globalVars: (0, import_env.getAutoInjectEnv)(appContext),
|
|
105
107
|
alias: defaultAlias,
|
|
106
108
|
moduleScopes: void 0,
|
|
107
109
|
include: []
|
|
@@ -34,7 +34,6 @@ __export(inits_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(inits_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
|
-
var import_env = require("../../utils/env");
|
|
38
37
|
function initHtmlConfig(config, appContext) {
|
|
39
38
|
const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "svg", "ico"];
|
|
40
39
|
config.html.appIcon = createBuilderAppIcon(config, appContext);
|
|
@@ -70,15 +69,9 @@ function initHtmlConfig(config, appContext) {
|
|
|
70
69
|
}
|
|
71
70
|
function initSourceConfig(config, appContext, bundler) {
|
|
72
71
|
config.source.include = createBuilderInclude(config, appContext);
|
|
73
|
-
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
74
72
|
if (bundler === "webpack") {
|
|
75
73
|
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
76
74
|
}
|
|
77
|
-
function createBuilderGlobalVars(config2, appContext2) {
|
|
78
|
-
const { globalVars = {} } = config2.source;
|
|
79
|
-
const publicEnv = (0, import_env.getAutoInjectEnv)(appContext2);
|
|
80
|
-
return { ...globalVars, ...publicEnv };
|
|
81
|
-
}
|
|
82
75
|
function createBuilderInclude(config2, appContext2) {
|
|
83
76
|
const { include } = config2.source;
|
|
84
77
|
const defaultInclude = [appContext2.internalDirectory];
|