@modern-js/app-tools 2.8.1-alpha.0 → 2.8.1-alpha.2
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/cjs/analyze/generateCode.js +1 -3
- package/dist/cjs/analyze/index.js +0 -8
- package/dist/cjs/analyze/templates.js +14 -31
- package/dist/cjs/builder/index.js +2 -0
- package/dist/esm/analyze/generateCode.js +2 -3
- package/dist/esm/analyze/index.js +0 -8
- package/dist/esm/analyze/templates.js +16 -30
- package/dist/esm/builder/index.js +2 -0
- package/dist/esm-node/analyze/generateCode.js +1 -3
- package/dist/esm-node/analyze/index.js +0 -8
- package/dist/esm-node/analyze/templates.js +14 -31
- package/dist/esm-node/builder/index.js +2 -0
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/analyze/templates.d.ts +1 -3
- package/dist/types/types/config/output.d.ts +0 -1
- package/package.json +11 -11
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
|
@@ -64,7 +64,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
|
|
67
|
-
var _a, _b, _c;
|
|
67
|
+
var _a, _b, _c, _d;
|
|
68
68
|
if (!(yield fs.pathExists(dirname))) {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
@@ -90,6 +90,8 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
90
90
|
};
|
|
91
91
|
let pageLoaderFile = "";
|
|
92
92
|
let pageRoute = null;
|
|
93
|
+
let splatLoaderFile = "";
|
|
94
|
+
let splatRoute = null;
|
|
93
95
|
const items = yield fs.readdir(dirname);
|
|
94
96
|
for (const item of items) {
|
|
95
97
|
const itemPath = path.join(dirname, item);
|
|
@@ -130,6 +132,24 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
130
132
|
}
|
|
131
133
|
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
132
134
|
}
|
|
135
|
+
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
136
|
+
splatLoaderFile = itemPath;
|
|
137
|
+
}
|
|
138
|
+
if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
|
|
139
|
+
splatRoute = createRoute(
|
|
140
|
+
{
|
|
141
|
+
_component: replaceWithAlias(alias.basename, itemPath, alias.name),
|
|
142
|
+
path: "*"
|
|
143
|
+
},
|
|
144
|
+
rootDir,
|
|
145
|
+
itemPath,
|
|
146
|
+
entryName
|
|
147
|
+
);
|
|
148
|
+
if (splatLoaderFile) {
|
|
149
|
+
splatRoute.loader = splatLoaderFile;
|
|
150
|
+
}
|
|
151
|
+
(_c = route.children) == null ? void 0 : _c.push(splatRoute);
|
|
152
|
+
}
|
|
133
153
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
134
154
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
135
155
|
}
|
|
@@ -137,7 +157,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
137
157
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
138
158
|
}
|
|
139
159
|
}
|
|
140
|
-
|
|
160
|
+
let finalRoute = createRoute(
|
|
141
161
|
route,
|
|
142
162
|
rootDir,
|
|
143
163
|
path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -146,10 +166,19 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
146
166
|
if (isPathlessLayout) {
|
|
147
167
|
delete finalRoute.path;
|
|
148
168
|
}
|
|
149
|
-
route.children = (
|
|
169
|
+
route.children = (_d = route.children) == null ? void 0 : _d.filter((childRoute) => childRoute);
|
|
150
170
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
151
171
|
return null;
|
|
152
172
|
}
|
|
173
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
174
|
+
const childRoute = finalRoute.children[0];
|
|
175
|
+
if (childRoute.path === "*") {
|
|
176
|
+
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
177
|
+
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
178
|
+
path: path2
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
153
182
|
return finalRoute;
|
|
154
183
|
});
|
|
155
184
|
export {
|
|
@@ -69,6 +69,7 @@ const renderFunction = ({
|
|
|
69
69
|
customBootstrap,
|
|
70
70
|
fileSystemRoutes: fileSystemRoutes2
|
|
71
71
|
}) => {
|
|
72
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
|
72
73
|
return `
|
|
73
74
|
const finalAppConfig = {
|
|
74
75
|
...App.config,
|
|
@@ -90,7 +91,7 @@ const renderFunction = ({
|
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
if (IS_BROWSER) {
|
|
93
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` :
|
|
94
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
return AppWrapper
|
|
@@ -198,7 +199,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
198
199
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
199
200
|
`;
|
|
200
201
|
let rootLayoutCode = ``;
|
|
201
|
-
let componentLoaderPath = "";
|
|
202
202
|
const getDataLoaderPath = (loaderId) => {
|
|
203
203
|
if (!ssrMode) {
|
|
204
204
|
return "";
|
|
@@ -211,12 +211,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
211
211
|
}
|
|
212
212
|
return dataLoaderPath;
|
|
213
213
|
};
|
|
214
|
-
if (ssrMode) {
|
|
215
|
-
componentLoaderPath = `${path.join(
|
|
216
|
-
__dirname,
|
|
217
|
-
"../builder/loaders/routerLoader"
|
|
218
|
-
)}!`;
|
|
219
|
-
}
|
|
220
214
|
const traverseRouteTree = (route) => {
|
|
221
215
|
var _a;
|
|
222
216
|
let children;
|
|
@@ -252,10 +246,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
252
246
|
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
253
247
|
component = `RootLayout`;
|
|
254
248
|
} else if (ssrMode === "string") {
|
|
255
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
249
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
256
250
|
component = `loadable(${lazyImport})`;
|
|
257
251
|
} else {
|
|
258
|
-
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${
|
|
252
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
259
253
|
component = `lazy(${lazyImport})`;
|
|
260
254
|
}
|
|
261
255
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
|
|
2
|
+
import { generateBuilder } from "../generator";
|
|
3
|
+
function createRspackBuilderForModern(options) {
|
|
4
|
+
return generateBuilder(options, builderRspackProvider);
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
createRspackBuilderForModern
|
|
8
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { createCopyPattern } from "../../shared";
|
|
3
|
+
import { RouterPlugin } from "../webpackPlugins";
|
|
4
|
+
const PluginCompatModern = (options) => ({
|
|
5
|
+
name: "builder-plugin-compat-modern",
|
|
6
|
+
setup(api) {
|
|
7
|
+
const { normalizedConfig: modernConfig, appContext } = options;
|
|
8
|
+
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
9
|
+
var _a;
|
|
10
|
+
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
11
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
12
|
+
const defaultCopyPattern = createCopyPattern(
|
|
13
|
+
appContext,
|
|
14
|
+
modernConfig,
|
|
15
|
+
"public",
|
|
16
|
+
chain
|
|
17
|
+
);
|
|
18
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
19
|
+
var _a2;
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const { entrypoints } = appContext;
|
|
28
|
+
const existNestedRoutes = entrypoints.some(
|
|
29
|
+
(entrypoint) => entrypoint.nestedRoutesEntry
|
|
30
|
+
);
|
|
31
|
+
const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
|
|
32
|
+
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
33
|
+
if (existNestedRoutes || routerManifest) {
|
|
34
|
+
chain.plugin("route-plugin").use(RouterPlugin);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
export {
|
|
40
|
+
PluginCompatModern
|
|
41
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import {
|
|
41
|
+
builderWebpackProvider
|
|
42
|
+
} from "@modern-js/builder-webpack-provider";
|
|
43
|
+
import { applyOptionsChain } from "@modern-js/utils";
|
|
44
|
+
import { createCopyPattern } from "../shared";
|
|
45
|
+
import { generateBuilder } from "../generator";
|
|
46
|
+
import { PluginCompatModern } from "./builderPlugins/compatModern";
|
|
47
|
+
function createWebpackBuilderForModern(options) {
|
|
48
|
+
return generateBuilder(options, builderWebpackProvider, {
|
|
49
|
+
modifyBuilderConfig(config) {
|
|
50
|
+
modifyOutputConfig(config, options.appContext);
|
|
51
|
+
},
|
|
52
|
+
modifyBuilderInstance(builder) {
|
|
53
|
+
return __async(this, null, function* () {
|
|
54
|
+
yield applyBuilderPlugins(builder, options);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function modifyOutputConfig(config, appContext) {
|
|
60
|
+
config.output = createOutputConfig(config, appContext);
|
|
61
|
+
function createOutputConfig(config2, appContext2) {
|
|
62
|
+
const defaultCopyPattern = createCopyPattern(appContext2, config2, "upload");
|
|
63
|
+
const { copy } = config2.output;
|
|
64
|
+
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
65
|
+
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
66
|
+
return __spreadProps(__spreadValues({}, config2.output), {
|
|
67
|
+
copy: builderCopy
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function applyBuilderPlugins(builder, options) {
|
|
72
|
+
return __async(this, null, function* () {
|
|
73
|
+
const { normalizedConfig } = options;
|
|
74
|
+
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
75
|
+
const { PluginNodePolyfill } = yield import("@modern-js/builder-plugin-node-polyfill");
|
|
76
|
+
builder.addPlugins([PluginNodePolyfill()]);
|
|
77
|
+
}
|
|
78
|
+
if (normalizedConfig.tools.esbuild) {
|
|
79
|
+
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
80
|
+
const { PluginEsbuild } = yield import("@modern-js/builder-plugin-esbuild");
|
|
81
|
+
builder.addPlugins([
|
|
82
|
+
PluginEsbuild({
|
|
83
|
+
loader: false,
|
|
84
|
+
minimize: applyOptionsChain({}, esbuildOptions)
|
|
85
|
+
})
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
builder.addPlugins([PluginCompatModern(options)]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
createWebpackBuilderForModern
|
|
93
|
+
};
|
|
@@ -32,6 +32,9 @@ class RouterPlugin {
|
|
|
32
32
|
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
+
if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
const { webpack } = compiler;
|
|
36
39
|
const { Compilation, sources } = webpack;
|
|
37
40
|
const { RawSource } = sources;
|
|
@@ -109,5 +112,5 @@ class RouterPlugin {
|
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
export {
|
|
112
|
-
RouterPlugin
|
|
115
|
+
RouterPlugin
|
|
113
116
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RouterPlugin";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function createBuilderOptions(target, appContext) {
|
|
2
|
+
const entries = {};
|
|
3
|
+
const { entrypoints = [], checkedEntries } = appContext;
|
|
4
|
+
for (const { entryName, entry } of entrypoints) {
|
|
5
|
+
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
6
|
+
continue;
|
|
7
|
+
}
|
|
8
|
+
if (entryName in entries) {
|
|
9
|
+
entries[entryName].push(entry);
|
|
10
|
+
} else {
|
|
11
|
+
entries[entryName] = [entry];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
cwd: appContext.appDirectory,
|
|
16
|
+
target,
|
|
17
|
+
configPath: appContext.configFile || void 0,
|
|
18
|
+
entry: entries,
|
|
19
|
+
framework: appContext.metaName
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
createBuilderOptions
|
|
24
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderConfig) {
|
|
21
|
+
const htmlConfig = __spreadValues({}, resolveConfig.html);
|
|
22
|
+
if (!htmlConfig.template) {
|
|
23
|
+
htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
|
|
24
|
+
}
|
|
25
|
+
const config = __spreadProps(__spreadValues({}, resolveConfig), {
|
|
26
|
+
dev: __spreadProps(__spreadValues({}, resolveConfig.dev), {
|
|
27
|
+
port: appContext.port
|
|
28
|
+
}),
|
|
29
|
+
html: htmlConfig,
|
|
30
|
+
output: __spreadProps(__spreadValues({}, resolveConfig.output), {
|
|
31
|
+
cleanDistPath: false
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
modifyBuilderConfig == null ? void 0 : modifyBuilderConfig(config);
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
createBuilderProviderConfig
|
|
39
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isProd,
|
|
3
|
+
isServiceWorker,
|
|
4
|
+
isSSR,
|
|
5
|
+
isUseSSRBundle
|
|
6
|
+
} from "@modern-js/utils";
|
|
7
|
+
function getBuilderTargets(normalizedConfig) {
|
|
8
|
+
const targets = ["web"];
|
|
9
|
+
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
|
10
|
+
if (useNodeTarget) {
|
|
11
|
+
targets.push("node");
|
|
12
|
+
}
|
|
13
|
+
const useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
|
|
14
|
+
if (useWorkerTarget) {
|
|
15
|
+
targets.push("service-worker");
|
|
16
|
+
}
|
|
17
|
+
return targets;
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
getBuilderTargets
|
|
21
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { createBuilder } from "@modern-js/builder";
|
|
22
|
+
import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
|
|
23
|
+
import { getBuilderTargets } from "./getBuilderTargets";
|
|
24
|
+
import { createBuilderOptions } from "./createBuilderOptions";
|
|
25
|
+
function generateBuilder(options, generateProvider, utils) {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
const { normalizedConfig, appContext } = options;
|
|
28
|
+
const { modifyBuilderConfig, modifyBuilderInstance } = utils || {};
|
|
29
|
+
const builderConfig = createBuilderProviderConfig(
|
|
30
|
+
normalizedConfig,
|
|
31
|
+
appContext,
|
|
32
|
+
modifyBuilderConfig
|
|
33
|
+
);
|
|
34
|
+
const provider = generateProvider({
|
|
35
|
+
builderConfig
|
|
36
|
+
});
|
|
37
|
+
const target = getBuilderTargets(normalizedConfig);
|
|
38
|
+
const builderOptions = createBuilderOptions(target, appContext);
|
|
39
|
+
const builder = yield createBuilder(provider, builderOptions);
|
|
40
|
+
yield applyBuilderPlugins(builder, options);
|
|
41
|
+
yield modifyBuilderInstance == null ? void 0 : modifyBuilderInstance(builder);
|
|
42
|
+
return builder;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function applyBuilderPlugins(builder, options) {
|
|
46
|
+
return __async(this, null, function* () {
|
|
47
|
+
const { builderPluginAdapterModern } = yield import("../shared/builderPlugins/adapterModern");
|
|
48
|
+
builder.addPlugins([builderPluginAdapterModern(options)]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
generateBuilder
|
|
53
|
+
};
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
1
|
var __async = (__this, __arguments, generator) => {
|
|
21
2
|
return new Promise((resolve, reject) => {
|
|
22
3
|
var fulfilled = (value) => {
|
|
@@ -37,123 +18,22 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
18
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
19
|
});
|
|
39
20
|
};
|
|
40
|
-
|
|
41
|
-
createBuilder
|
|
42
|
-
} from "@modern-js/builder";
|
|
43
|
-
import {
|
|
44
|
-
builderWebpackProvider
|
|
45
|
-
} from "@modern-js/builder-webpack-provider";
|
|
46
|
-
import {
|
|
47
|
-
applyOptionsChain,
|
|
48
|
-
isProd,
|
|
49
|
-
isSSR,
|
|
50
|
-
isUseSSRBundle
|
|
51
|
-
} from "@modern-js/utils";
|
|
52
|
-
import {
|
|
53
|
-
PluginCompatModern
|
|
54
|
-
} from "./builderPlugins/compatModern";
|
|
55
|
-
import { createCopyPattern } from "./share";
|
|
56
|
-
function getBuilderTargets(normalizedConfig) {
|
|
57
|
-
const targets = ["web"];
|
|
58
|
-
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
|
59
|
-
if (useNodeTarget) {
|
|
60
|
-
targets.push("node");
|
|
61
|
-
}
|
|
62
|
-
return targets;
|
|
63
|
-
}
|
|
64
|
-
function createBuilderForModern(_0) {
|
|
65
|
-
return __async(this, arguments, function* ({
|
|
66
|
-
normalizedConfig,
|
|
67
|
-
appContext,
|
|
68
|
-
compatPluginConfig
|
|
69
|
-
}) {
|
|
70
|
-
const builderConfig = createBuilderProviderConfig(
|
|
71
|
-
normalizedConfig,
|
|
72
|
-
appContext
|
|
73
|
-
);
|
|
74
|
-
const webpackProvider = builderWebpackProvider({
|
|
75
|
-
builderConfig
|
|
76
|
-
});
|
|
77
|
-
const target = getBuilderTargets(normalizedConfig);
|
|
78
|
-
const builderOptions = createBuilderOptions(target, appContext);
|
|
79
|
-
const builder = yield createBuilder(webpackProvider, builderOptions);
|
|
80
|
-
yield applyBuilderPlugins(
|
|
81
|
-
builder,
|
|
82
|
-
normalizedConfig,
|
|
83
|
-
appContext,
|
|
84
|
-
compatPluginConfig
|
|
85
|
-
);
|
|
86
|
-
return builder;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
90
|
-
const output = createOutputConfig(normalizedConfig, appContext);
|
|
91
|
-
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
92
|
-
if (!htmlConfig.template) {
|
|
93
|
-
htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
|
|
94
|
-
}
|
|
95
|
-
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
96
|
-
output,
|
|
97
|
-
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
98
|
-
port: appContext.port
|
|
99
|
-
}),
|
|
100
|
-
html: htmlConfig
|
|
101
|
-
});
|
|
102
|
-
function createOutputConfig(config, appContext2) {
|
|
103
|
-
const defaultCopyPattern = createCopyPattern(appContext2, config, "upload");
|
|
104
|
-
const { copy } = config.output;
|
|
105
|
-
const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
|
|
106
|
-
const builderCopy = [...copyOptions || [], defaultCopyPattern];
|
|
107
|
-
return __spreadProps(__spreadValues({}, config.output), {
|
|
108
|
-
copy: builderCopy,
|
|
109
|
-
cleanDistPath: false
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function createBuilderOptions(target, appContext) {
|
|
114
|
-
const entries = {};
|
|
115
|
-
const { entrypoints = [], checkedEntries } = appContext;
|
|
116
|
-
for (const { entryName, entry } of entrypoints) {
|
|
117
|
-
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (entryName in entries) {
|
|
121
|
-
entries[entryName].push(entry);
|
|
122
|
-
} else {
|
|
123
|
-
entries[entryName] = [entry];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
cwd: appContext.appDirectory,
|
|
128
|
-
target,
|
|
129
|
-
configPath: appContext.configFile || void 0,
|
|
130
|
-
entry: entries,
|
|
131
|
-
framework: appContext.metaName
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
21
|
+
function createBuilderGenerator(bundler) {
|
|
135
22
|
return __async(this, null, function* () {
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
loader: false,
|
|
146
|
-
minimize: applyOptionsChain({}, esbuildOptions)
|
|
147
|
-
})
|
|
148
|
-
]);
|
|
23
|
+
if (bundler === "rspack") {
|
|
24
|
+
try {
|
|
25
|
+
const { createRspackBuilderForModern } = yield import("./builder-rspack");
|
|
26
|
+
return createRspackBuilderForModern;
|
|
27
|
+
} catch (_) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
149
32
|
}
|
|
150
|
-
builder
|
|
151
|
-
|
|
152
|
-
]);
|
|
33
|
+
const { createWebpackBuilderForModern } = yield import("./builder-webpack");
|
|
34
|
+
return createWebpackBuilderForModern;
|
|
153
35
|
});
|
|
154
36
|
}
|
|
155
37
|
export {
|
|
156
|
-
|
|
157
|
-
createBuilderOptions,
|
|
158
|
-
createBuilderProviderConfig
|
|
38
|
+
createBuilderGenerator
|
|
159
39
|
};
|