@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/dist/esm/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js}
RENAMED
|
@@ -24,17 +24,17 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
24
24
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
25
25
|
}
|
|
26
26
|
import { join } from "path";
|
|
27
|
-
import {
|
|
28
|
-
var
|
|
27
|
+
import { createPublicPattern } from "./createCopyPattern";
|
|
28
|
+
var builderPluginAdapterModern = function(options) {
|
|
29
29
|
return {
|
|
30
|
-
name: "builder-plugin-
|
|
30
|
+
name: "builder-plugin-adapter-",
|
|
31
31
|
setup: function setup(api) {
|
|
32
32
|
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
|
33
33
|
api.modifyWebpackChain(function(chain, param) {
|
|
34
34
|
var CHAIN_ID = param.CHAIN_ID;
|
|
35
35
|
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
36
36
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
37
|
-
var defaultCopyPattern =
|
|
37
|
+
var defaultCopyPattern = createPublicPattern(appContext, modernConfig, chain);
|
|
38
38
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function(args) {
|
|
39
39
|
var _args_;
|
|
40
40
|
return [
|
|
@@ -50,4 +50,4 @@ var builderPluginCompatModern = function(options) {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
-
export {
|
|
53
|
+
export { builderPluginAdapterModern };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { removeTailSlash } from "@modern-js/utils";
|
|
2
|
+
import { createCopyInfo } from "../shared";
|
|
3
|
+
var minifiedJsRexExp = /\.min\.js/;
|
|
4
|
+
var info = function(file) {
|
|
5
|
+
return {
|
|
6
|
+
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
7
|
+
// So we don't want copy-webpack-plugin to minify it.
|
|
8
|
+
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
9
|
+
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
function createPublicPattern(appContext, config, chain) {
|
|
13
|
+
var publicDir = createCopyInfo(appContext, config).publicDir;
|
|
14
|
+
return {
|
|
15
|
+
info: info,
|
|
16
|
+
from: "**/*",
|
|
17
|
+
to: "public",
|
|
18
|
+
context: publicDir,
|
|
19
|
+
noErrorOnMissing: true,
|
|
20
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
21
|
+
transform: function(content, absoluteFrom) {
|
|
22
|
+
if (!/\.html?$/.test(absoluteFrom)) {
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
return content.toString("utf8").replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(chain.output.get("publicPath")));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createUploadPattern(appContext, config) {
|
|
30
|
+
var uploadDir = createCopyInfo(appContext, config).uploadDir;
|
|
31
|
+
return {
|
|
32
|
+
info: info,
|
|
33
|
+
from: "**/*",
|
|
34
|
+
to: "upload",
|
|
35
|
+
context: uploadDir,
|
|
36
|
+
noErrorOnMissing: true
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export { createPublicPattern, createUploadPattern };
|
|
@@ -200,9 +200,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
|
|
203
|
-
import { createCopyPattern } from "../shared";
|
|
204
203
|
import { generateBuilder } from "../generator";
|
|
205
|
-
import {
|
|
204
|
+
import { builderPluginAdapterModern } from "./adapterModern";
|
|
205
|
+
import { createUploadPattern } from "./createCopyPattern";
|
|
206
206
|
function createWebpackBuilderForModern(options) {
|
|
207
207
|
return generateBuilder(options, builderWebpackProvider, {
|
|
208
208
|
modifyBuilderConfig: function modifyBuilderConfig(config) {
|
|
@@ -230,7 +230,7 @@ function createWebpackBuilderForModern(options) {
|
|
|
230
230
|
}
|
|
231
231
|
function modifyOutputConfig(config, appContext) {
|
|
232
232
|
var createOutputConfig = function createOutputConfig(config2, appContext2) {
|
|
233
|
-
var defaultCopyPattern =
|
|
233
|
+
var defaultCopyPattern = createUploadPattern(appContext2, config2);
|
|
234
234
|
var copy = config2.output.copy;
|
|
235
235
|
var copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
|
236
236
|
var builderCopy = _toConsumableArray(copyOptions || []).concat([
|
|
@@ -269,7 +269,7 @@ function _applyBuilderPlugins() {
|
|
|
269
269
|
_state.label = 2;
|
|
270
270
|
case 2:
|
|
271
271
|
builder.addPlugins([
|
|
272
|
-
|
|
272
|
+
builderPluginAdapterModern(options)
|
|
273
273
|
]);
|
|
274
274
|
return [
|
|
275
275
|
2
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
function createCopyInfo(appContext, config) {
|
|
3
|
+
var configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
|
|
4
|
+
var uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
|
|
5
|
+
var publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
|
|
6
|
+
return {
|
|
7
|
+
configDir: configDir,
|
|
8
|
+
uploadDir: uploadDir,
|
|
9
|
+
publicDir: publicDir
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export { createCopyInfo };
|
|
@@ -51,6 +51,7 @@ function _objectSpreadProps(target, source) {
|
|
|
51
51
|
return target;
|
|
52
52
|
}
|
|
53
53
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
54
|
+
import { getAutoInjectEnv } from "../utils/env";
|
|
54
55
|
function createDefaultConfig(appContext, bundler) {
|
|
55
56
|
var defaultBuilderConfig = createDefaultBuilderConfig();
|
|
56
57
|
var dev = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.dev), {
|
|
@@ -68,6 +69,7 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
68
69
|
disableDefaultEntries: false,
|
|
69
70
|
entriesDir: "./src",
|
|
70
71
|
configDir: "./config",
|
|
72
|
+
globalVars: getAutoInjectEnv(appContext),
|
|
71
73
|
alias: (_obj = {}, _defineProperty(_obj, appContext.internalDirAlias, appContext.internalDirectory), _defineProperty(_obj, appContext.internalSrcAlias, appContext.srcDirectory), _defineProperty(_obj, "@", appContext.srcDirectory), _defineProperty(_obj, "@shared", appContext.sharedDirectory), _obj)
|
|
72
74
|
});
|
|
73
75
|
var html = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.html), {
|
|
@@ -121,7 +123,7 @@ function createLegacyDefaultConfig(appContext) {
|
|
|
121
123
|
configDir: "./config",
|
|
122
124
|
apiDir: "./api",
|
|
123
125
|
envVars: [],
|
|
124
|
-
globalVars:
|
|
126
|
+
globalVars: getAutoInjectEnv(appContext),
|
|
125
127
|
alias: defaultAlias,
|
|
126
128
|
moduleScopes: void 0,
|
|
127
129
|
include: []
|
|
@@ -77,7 +77,6 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
77
77
|
}
|
|
78
78
|
import path, { dirname, isAbsolute, posix, sep } from "path";
|
|
79
79
|
import { applyOptionsChain, findExists, findMonorepoRoot, globby, isModernjsMonorepo } from "@modern-js/utils";
|
|
80
|
-
import { getAutoInjectEnv } from "../../utils/env";
|
|
81
80
|
function initHtmlConfig(config, appContext) {
|
|
82
81
|
var createBuilderAppIcon = function createBuilderAppIcon(config2, appContext2) {
|
|
83
82
|
var configDir = config2.source.configDir;
|
|
@@ -106,11 +105,6 @@ function initHtmlConfig(config, appContext) {
|
|
|
106
105
|
return config.html;
|
|
107
106
|
}
|
|
108
107
|
function initSourceConfig(config, appContext, bundler) {
|
|
109
|
-
var createBuilderGlobalVars = function createBuilderGlobalVars(config2, appContext2) {
|
|
110
|
-
var _config2_source = config2.source, _config2_source_globalVars = _config2_source.globalVars, globalVars = _config2_source_globalVars === void 0 ? {} : _config2_source_globalVars;
|
|
111
|
-
var publicEnv = getAutoInjectEnv(appContext2);
|
|
112
|
-
return _objectSpread({}, globalVars, publicEnv);
|
|
113
|
-
};
|
|
114
108
|
var createBuilderInclude = function createBuilderInclude(config2, appContext2) {
|
|
115
109
|
var include = config2.source.include;
|
|
116
110
|
var defaultInclude = [
|
|
@@ -176,7 +170,6 @@ function initSourceConfig(config, appContext, bundler) {
|
|
|
176
170
|
}
|
|
177
171
|
};
|
|
178
172
|
config.source.include = createBuilderInclude(config, appContext);
|
|
179
|
-
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
180
173
|
if (bundler === "webpack") {
|
|
181
174
|
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
182
175
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -583,7 +583,7 @@ var src_default = function() {
|
|
|
583
583
|
return _ref.apply(this, arguments);
|
|
584
584
|
};
|
|
585
585
|
}());
|
|
586
|
-
program.command("inspect").description("inspect internal
|
|
586
|
+
program.command("inspect").description("inspect the internal configs").option("--env <env>", i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(function() {
|
|
587
587
|
var _ref = _asyncToGenerator(function(options2) {
|
|
588
588
|
var inspect;
|
|
589
589
|
return __generator(this, function(_state) {
|
|
@@ -616,7 +616,7 @@ var src_default = function() {
|
|
|
616
616
|
},
|
|
617
617
|
prepare: function prepare() {
|
|
618
618
|
return _asyncToGenerator(function() {
|
|
619
|
-
var command, appContext;
|
|
619
|
+
var command, resolvedConfig, appContext;
|
|
620
620
|
return __generator(this, function(_state) {
|
|
621
621
|
switch(_state.label){
|
|
622
622
|
case 0:
|
|
@@ -625,6 +625,11 @@ var src_default = function() {
|
|
|
625
625
|
3,
|
|
626
626
|
2
|
|
627
627
|
];
|
|
628
|
+
resolvedConfig = api.useResolvedConfigContext();
|
|
629
|
+
if (!resolvedConfig.output.cleanDistPath) return [
|
|
630
|
+
3,
|
|
631
|
+
2
|
|
632
|
+
];
|
|
628
633
|
appContext = api.useAppContext();
|
|
629
634
|
return [
|
|
630
635
|
4,
|
package/dist/esm/locale/en.js
CHANGED
|
@@ -5,7 +5,7 @@ var EN_LOCALE = {
|
|
|
5
5
|
config: "specify config file"
|
|
6
6
|
},
|
|
7
7
|
dev: {
|
|
8
|
-
describe: "
|
|
8
|
+
describe: "starting the dev server",
|
|
9
9
|
entry: "compiler by entry",
|
|
10
10
|
apiOnly: "start api server only",
|
|
11
11
|
webOnly: "start web server only",
|
|
@@ -13,16 +13,16 @@ var EN_LOCALE = {
|
|
|
13
13
|
requireEntry: "You must choose at least one entry"
|
|
14
14
|
},
|
|
15
15
|
build: {
|
|
16
|
-
describe: "build
|
|
16
|
+
describe: "build the app for production"
|
|
17
17
|
},
|
|
18
18
|
serve: {
|
|
19
|
-
describe: "
|
|
19
|
+
describe: "preview the production build locally"
|
|
20
20
|
},
|
|
21
21
|
deploy: {
|
|
22
|
-
describe: "deploy application"
|
|
22
|
+
describe: "deploy the application"
|
|
23
23
|
},
|
|
24
24
|
new: {
|
|
25
|
-
describe: "
|
|
25
|
+
describe: "enable optional features or add a new entry",
|
|
26
26
|
debug: "using debug mode to log something",
|
|
27
27
|
config: "set default generator config(json string)",
|
|
28
28
|
distTag: "use specified tag version for it's generator",
|
package/dist/esm/locale/zh.js
CHANGED
|
@@ -5,7 +5,7 @@ var ZH_LOCALE = {
|
|
|
5
5
|
config: "指定配置文件路径,可以为相对路径或绝对路径"
|
|
6
6
|
},
|
|
7
7
|
dev: {
|
|
8
|
-
describe: "
|
|
8
|
+
describe: "启动开发服务器",
|
|
9
9
|
entry: "指定入口,编译特定的页面",
|
|
10
10
|
apiOnly: "仅启动 API 接口服务",
|
|
11
11
|
webOnly: "仅启动 Web 服务",
|
|
@@ -13,13 +13,13 @@ var ZH_LOCALE = {
|
|
|
13
13
|
requireEntry: "请至少选择一个入口"
|
|
14
14
|
},
|
|
15
15
|
build: {
|
|
16
|
-
describe: "
|
|
16
|
+
describe: "构建生产环境产物"
|
|
17
17
|
},
|
|
18
18
|
serve: {
|
|
19
|
-
describe: "
|
|
19
|
+
describe: "启动生产环境服务"
|
|
20
20
|
},
|
|
21
21
|
deploy: {
|
|
22
|
-
describe: "
|
|
22
|
+
describe: "部署应用"
|
|
23
23
|
},
|
|
24
24
|
new: {
|
|
25
25
|
describe: "Web App 项目中执行生成器",
|
|
@@ -25,7 +25,9 @@ const NESTED_ROUTE = {
|
|
|
25
25
|
ERROR_FILE: "error",
|
|
26
26
|
LOADER_FILE: "loader",
|
|
27
27
|
SPLATE_FILE: "$",
|
|
28
|
-
SPLATE_LOADER_FILE: "$.loader"
|
|
28
|
+
SPLATE_LOADER_FILE: "$.loader",
|
|
29
|
+
LAYOUT_CONFIG_FILE: "layout.config",
|
|
30
|
+
PAGE_CONFIG_FILE: "page.config"
|
|
29
31
|
};
|
|
30
32
|
const APP_CONFIG_NAME = "config";
|
|
31
33
|
const APP_INIT_EXPORTED = "init";
|
|
@@ -75,12 +75,15 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
75
75
|
return routes;
|
|
76
76
|
};
|
|
77
77
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
78
|
+
var _a;
|
|
78
79
|
const {
|
|
79
80
|
html: { disableHtmlFolder },
|
|
80
81
|
output: { distPath: { html: htmlPath } = {} },
|
|
81
|
-
server: { baseUrl, routes, ssr, ssrByEntries
|
|
82
|
+
server: { baseUrl, routes, ssr, ssrByEntries },
|
|
83
|
+
deploy
|
|
82
84
|
} = config;
|
|
83
85
|
const { packageName } = appContext;
|
|
86
|
+
const workerSSR = (_a = deploy == null ? void 0 : deploy.worker) == null ? void 0 : _a.ssr;
|
|
84
87
|
let htmlRoutes = entrypoints.reduce(
|
|
85
88
|
(previous, { entryName }) => {
|
|
86
89
|
const entryOptions = getEntryOptions(
|
|
@@ -90,7 +93,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
90
93
|
packageName
|
|
91
94
|
);
|
|
92
95
|
const isSSR = Boolean(entryOptions);
|
|
93
|
-
const isWorker = Boolean(
|
|
96
|
+
const isWorker = Boolean(workerSSR);
|
|
94
97
|
const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
|
|
95
98
|
let route = {
|
|
96
99
|
urlPath: `/${entryName === MAIN_ENTRY_NAME ? "" : entryName}`,
|
|
@@ -55,6 +55,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
55
55
|
let pageRoute = null;
|
|
56
56
|
let splatLoaderFile = "";
|
|
57
57
|
let splatRoute = null;
|
|
58
|
+
let pageConfigFile = "";
|
|
58
59
|
const items = await fs.readdir(dirname);
|
|
59
60
|
for (const item of items) {
|
|
60
61
|
const itemPath = path.join(dirname, item);
|
|
@@ -75,12 +76,20 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
75
76
|
route.loader = itemPath;
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
|
|
80
|
+
if (!route.config) {
|
|
81
|
+
route.config = itemPath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
78
84
|
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
|
|
79
85
|
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
80
86
|
}
|
|
81
87
|
if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
82
88
|
pageLoaderFile = itemPath;
|
|
83
89
|
}
|
|
90
|
+
if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
|
|
91
|
+
pageConfigFile = itemPath;
|
|
92
|
+
}
|
|
84
93
|
if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
|
|
85
94
|
pageRoute = createIndexRoute(
|
|
86
95
|
{
|
|
@@ -93,6 +102,9 @@ const walk = async (dirname, rootDir, alias, entryName) => {
|
|
|
93
102
|
if (pageLoaderFile) {
|
|
94
103
|
pageRoute.loader = pageLoaderFile;
|
|
95
104
|
}
|
|
105
|
+
if (pageConfigFile) {
|
|
106
|
+
pageRoute.config = pageConfigFile;
|
|
107
|
+
}
|
|
96
108
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
97
109
|
}
|
|
98
110
|
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
@@ -150,6 +150,8 @@ const fileSystemRoutes = async ({
|
|
|
150
150
|
const errors = [];
|
|
151
151
|
const loaders = [];
|
|
152
152
|
const loadersMap = {};
|
|
153
|
+
const configs = [];
|
|
154
|
+
const configsMap = {};
|
|
153
155
|
const loadersMapFile = path.join(
|
|
154
156
|
internalDirectory,
|
|
155
157
|
entryName,
|
|
@@ -179,6 +181,7 @@ const fileSystemRoutes = async ({
|
|
|
179
181
|
let loading;
|
|
180
182
|
let error;
|
|
181
183
|
let loader;
|
|
184
|
+
let config;
|
|
182
185
|
let component = "";
|
|
183
186
|
let lazyImport = null;
|
|
184
187
|
if (route.type === "nested") {
|
|
@@ -200,6 +203,12 @@ const fileSystemRoutes = async ({
|
|
|
200
203
|
inline: false
|
|
201
204
|
};
|
|
202
205
|
}
|
|
206
|
+
if (typeof route.config === "string") {
|
|
207
|
+
configs.push(route.config);
|
|
208
|
+
const configId = configs.length - 1;
|
|
209
|
+
config = `config_${configId}`;
|
|
210
|
+
configsMap[config] = route.config;
|
|
211
|
+
}
|
|
203
212
|
if (route._component) {
|
|
204
213
|
if (splitRouteChunks) {
|
|
205
214
|
if (route.isRoot) {
|
|
@@ -231,6 +240,7 @@ const fileSystemRoutes = async ({
|
|
|
231
240
|
lazyImport,
|
|
232
241
|
loading,
|
|
233
242
|
loader,
|
|
243
|
+
config,
|
|
234
244
|
error,
|
|
235
245
|
children
|
|
236
246
|
};
|
|
@@ -251,7 +261,8 @@ const fileSystemRoutes = async ({
|
|
|
251
261
|
"lazyImport",
|
|
252
262
|
"loader",
|
|
253
263
|
"loading",
|
|
254
|
-
"error"
|
|
264
|
+
"error",
|
|
265
|
+
"config"
|
|
255
266
|
];
|
|
256
267
|
const regs = keywords.map(createMatchReg);
|
|
257
268
|
const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
|
|
@@ -297,6 +308,11 @@ const fileSystemRoutes = async ({
|
|
|
297
308
|
`;
|
|
298
309
|
}
|
|
299
310
|
}
|
|
311
|
+
let importConfigsCode = "";
|
|
312
|
+
for (const [key, configPath] of Object.entries(configsMap)) {
|
|
313
|
+
importConfigsCode += `import * as ${key} from "${slash(configPath)}";
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
300
316
|
await fs.ensureFile(loadersMapFile);
|
|
301
317
|
await fs.writeJSON(loadersMapFile, loadersMap);
|
|
302
318
|
return `
|
|
@@ -306,6 +322,7 @@ const fileSystemRoutes = async ({
|
|
|
306
322
|
${importLoadingCode}
|
|
307
323
|
${importErrorComponentsCode}
|
|
308
324
|
${importLoadersCode}
|
|
325
|
+
${importConfigsCode}
|
|
309
326
|
${routeComponentsCode}
|
|
310
327
|
`;
|
|
311
328
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "@modern-js/utils/fs-extra";
|
|
3
|
+
import { logger, removeTailSlash } from "@modern-js/utils";
|
|
4
|
+
import { createCopyInfo } from "../shared";
|
|
5
|
+
const builderPluginAdpaterCopy = (options) => ({
|
|
6
|
+
name: "builder-plugin-adapter-rspack-copy",
|
|
7
|
+
setup(api) {
|
|
8
|
+
let publicPath;
|
|
9
|
+
api.modifyRspackConfig((config) => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
config.builtins = {
|
|
12
|
+
...config.builtins || {},
|
|
13
|
+
copy: {
|
|
14
|
+
patterns: [
|
|
15
|
+
...transformCopy((_b = (_a = config.builtins) == null ? void 0 : _a.copy) == null ? void 0 : _b.patterns),
|
|
16
|
+
...createConfigBuiltinCopy(options)
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
publicPath = (_c = config.output) == null ? void 0 : _c.publicPath;
|
|
21
|
+
});
|
|
22
|
+
api.onDevCompileDone(async () => {
|
|
23
|
+
await transformHtmlFiles();
|
|
24
|
+
});
|
|
25
|
+
api.onAfterBuild(async () => {
|
|
26
|
+
await transformHtmlFiles();
|
|
27
|
+
});
|
|
28
|
+
async function transformHtmlFiles() {
|
|
29
|
+
var _a;
|
|
30
|
+
const { normalizedConfig } = options;
|
|
31
|
+
const publicDir = path.resolve(
|
|
32
|
+
((_a = normalizedConfig.output.distPath) == null ? void 0 : _a.root) || "./dist",
|
|
33
|
+
"./public"
|
|
34
|
+
);
|
|
35
|
+
if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const HTML_REGEXP = /\.html?$/;
|
|
39
|
+
const filepaths = (await fs.readdir(publicDir)).map(
|
|
40
|
+
(file) => path.resolve(publicDir, file)
|
|
41
|
+
);
|
|
42
|
+
await Promise.all(
|
|
43
|
+
filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
|
44
|
+
const content = await fs.readFile(file, "utf-8");
|
|
45
|
+
if (publicPath) {
|
|
46
|
+
await fs.writeFile(
|
|
47
|
+
file,
|
|
48
|
+
content.replace(
|
|
49
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
50
|
+
removeTailSlash(publicPath)
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
logger.warn(
|
|
55
|
+
"Expect get a string from `publicPath`, but receive `undefined`."
|
|
56
|
+
);
|
|
57
|
+
await fs.writeFile(
|
|
58
|
+
file,
|
|
59
|
+
content.replace(
|
|
60
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
61
|
+
removeTailSlash("/")
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
function transformCopy(patterns) {
|
|
71
|
+
if (patterns) {
|
|
72
|
+
patterns.map((value) => {
|
|
73
|
+
if (typeof value === "string") {
|
|
74
|
+
return {
|
|
75
|
+
from: value
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
function createConfigBuiltinCopy(options) {
|
|
84
|
+
const { normalizedConfig, appContext } = options;
|
|
85
|
+
const { uploadDir, publicDir } = createCopyInfo(appContext, normalizedConfig);
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
from: "**/*",
|
|
89
|
+
to: "public",
|
|
90
|
+
context: publicDir,
|
|
91
|
+
noErrorOnMissing: true
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
from: "**/*",
|
|
95
|
+
to: "upload",
|
|
96
|
+
context: uploadDir,
|
|
97
|
+
noErrorOnMissing: true
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
builderPluginAdpaterCopy
|
|
103
|
+
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
|
|
2
2
|
import { generateBuilder } from "../generator";
|
|
3
|
+
import { builderPluginAdpaterCopy } from "./adapterCopy";
|
|
3
4
|
function createRspackBuilderForModern(options) {
|
|
4
|
-
return generateBuilder(options, builderRspackProvider
|
|
5
|
+
return generateBuilder(options, builderRspackProvider, {
|
|
6
|
+
modifyBuilderInstance(builder) {
|
|
7
|
+
builder.addPlugins([builderPluginAdpaterCopy(options)]);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
5
10
|
}
|
|
6
11
|
export {
|
|
7
12
|
createRspackBuilderForModern
|
package/dist/esm-node/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js}
RENAMED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
name: "builder-plugin-
|
|
2
|
+
import { createPublicPattern } from "./createCopyPattern";
|
|
3
|
+
const builderPluginAdapterModern = (options) => ({
|
|
4
|
+
name: "builder-plugin-adapter-",
|
|
5
5
|
setup(api) {
|
|
6
6
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
7
7
|
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
8
8
|
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
9
9
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
10
|
-
const defaultCopyPattern =
|
|
10
|
+
const defaultCopyPattern = createPublicPattern(
|
|
11
11
|
appContext,
|
|
12
12
|
modernConfig,
|
|
13
|
-
"public",
|
|
14
13
|
chain
|
|
15
14
|
);
|
|
16
15
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
@@ -26,5 +25,5 @@ const builderPluginCompatModern = (options) => ({
|
|
|
26
25
|
}
|
|
27
26
|
});
|
|
28
27
|
export {
|
|
29
|
-
|
|
28
|
+
builderPluginAdapterModern
|
|
30
29
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { removeTailSlash } from "@modern-js/utils";
|
|
2
|
+
import { createCopyInfo } from "../shared";
|
|
3
|
+
const minifiedJsRexExp = /\.min\.js/;
|
|
4
|
+
const info = (file) => ({
|
|
5
|
+
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
6
|
+
// So we don't want copy-webpack-plugin to minify it.
|
|
7
|
+
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
8
|
+
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
9
|
+
});
|
|
10
|
+
function createPublicPattern(appContext, config, chain) {
|
|
11
|
+
const { publicDir } = createCopyInfo(appContext, config);
|
|
12
|
+
return {
|
|
13
|
+
info,
|
|
14
|
+
from: "**/*",
|
|
15
|
+
to: "public",
|
|
16
|
+
context: publicDir,
|
|
17
|
+
noErrorOnMissing: true,
|
|
18
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
19
|
+
transform: (content, absoluteFrom) => {
|
|
20
|
+
if (!/\.html?$/.test(absoluteFrom)) {
|
|
21
|
+
return content;
|
|
22
|
+
}
|
|
23
|
+
return content.toString("utf8").replace(
|
|
24
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
25
|
+
removeTailSlash(chain.output.get("publicPath"))
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createUploadPattern(appContext, config) {
|
|
31
|
+
const { uploadDir } = createCopyInfo(appContext, config);
|
|
32
|
+
return {
|
|
33
|
+
info,
|
|
34
|
+
from: "**/*",
|
|
35
|
+
to: "upload",
|
|
36
|
+
context: uploadDir,
|
|
37
|
+
noErrorOnMissing: true
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
createPublicPattern,
|
|
42
|
+
createUploadPattern
|
|
43
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
builderWebpackProvider
|
|
3
3
|
} from "@modern-js/builder-webpack-provider";
|
|
4
|
-
import { createCopyPattern } from "../shared";
|
|
5
4
|
import { generateBuilder } from "../generator";
|
|
6
|
-
import {
|
|
5
|
+
import { builderPluginAdapterModern } from "./adapterModern";
|
|
6
|
+
import { createUploadPattern } from "./createCopyPattern";
|
|
7
7
|
function createWebpackBuilderForModern(options) {
|
|
8
8
|
return generateBuilder(options, builderWebpackProvider, {
|
|
9
9
|
modifyBuilderConfig(config) {
|
|
@@ -17,7 +17,7 @@ function createWebpackBuilderForModern(options) {
|
|
|
17
17
|
function modifyOutputConfig(config, appContext) {
|
|
18
18
|
config.output = createOutputConfig(config, appContext);
|
|
19
19
|
function createOutputConfig(config2, appContext2) {
|
|
20
|
-
const defaultCopyPattern =
|
|
20
|
+
const defaultCopyPattern = createUploadPattern(appContext2, config2);
|
|
21
21
|
const { copy } = config2.output;
|
|
22
22
|
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
23
23
|
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
@@ -34,7 +34,7 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
34
34
|
const { builderPluginEsbuild } = await import("@modern-js/builder-plugin-esbuild");
|
|
35
35
|
builder.addPlugins([builderPluginEsbuild(esbuildOptions)]);
|
|
36
36
|
}
|
|
37
|
-
builder.addPlugins([
|
|
37
|
+
builder.addPlugins([builderPluginAdapterModern(options)]);
|
|
38
38
|
}
|
|
39
39
|
export {
|
|
40
40
|
createWebpackBuilderForModern
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
function createCopyInfo(appContext, config) {
|
|
3
|
+
const configDir = path.resolve(
|
|
4
|
+
appContext.appDirectory,
|
|
5
|
+
config.source.configDir || "./config"
|
|
6
|
+
);
|
|
7
|
+
const uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
|
|
8
|
+
const publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
|
|
9
|
+
return {
|
|
10
|
+
configDir,
|
|
11
|
+
uploadDir,
|
|
12
|
+
publicDir
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
createCopyInfo
|
|
17
|
+
};
|