@modern-js/app-tools 2.0.0-canary.0 → 2.0.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 +724 -0
- package/bin/modern.js +3 -0
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +16 -0
- package/dist/js/modern/analyze/generateCode.js +14 -15
- package/dist/js/modern/analyze/getBundleEntry.js +5 -1
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +9 -6
- package/dist/js/modern/analyze/getFileSystemEntry.js +11 -3
- package/dist/js/modern/analyze/index.js +79 -8
- package/dist/js/modern/analyze/nestedRoutes.js +29 -22
- package/dist/js/modern/analyze/templates.js +28 -7
- package/dist/js/modern/analyze/utils.js +21 -4
- package/dist/js/modern/builder/builderPlugins/compatModern.js +12 -5
- package/dist/js/modern/builder/index.js +14 -16
- package/dist/js/modern/builder/share.js +4 -4
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +3 -1
- package/dist/js/modern/commands/dev.js +6 -9
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/{start.js → serve.js} +3 -1
- package/dist/js/modern/config/default.js +38 -61
- package/dist/js/modern/config/initial/createOutputConfig.js +1 -3
- package/dist/js/modern/config/initial/createSourceConfig.js +5 -1
- package/dist/js/modern/config/initial/inits.js +7 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +5 -1
- package/dist/js/modern/hooks.js +6 -1
- package/dist/js/modern/index.js +96 -59
- package/dist/js/modern/initialize/index.js +5 -4
- package/dist/js/modern/locale/en.js +1 -1
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/schema/index.js +6 -8
- package/dist/js/modern/schema/legacy.js +2 -3
- package/dist/js/modern/utils/commands.js +6 -1
- package/dist/js/modern/utils/env.js +15 -0
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/node/analyze/Builder.js +64 -0
- package/dist/js/node/analyze/constants.js +44 -3
- package/dist/js/node/analyze/generateCode.js +33 -29
- package/dist/js/node/analyze/getBundleEntry.js +12 -4
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +33 -28
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +24 -22
- package/dist/js/node/analyze/getClientRoutes/index.js +8 -3
- package/dist/js/node/analyze/getClientRoutes/utils.js +10 -3
- package/dist/js/node/analyze/getFileSystemEntry.js +18 -6
- package/dist/js/node/analyze/getHtmlTemplate.js +18 -14
- package/dist/js/node/analyze/getServerRoutes.js +36 -34
- package/dist/js/node/analyze/index.js +105 -59
- package/dist/js/node/analyze/isDefaultExportFunction.js +7 -3
- package/dist/js/node/analyze/makeLegalIdentifier.js +7 -3
- package/dist/js/node/analyze/nestedRoutes.js +58 -49
- package/dist/js/node/analyze/templates.js +64 -37
- package/dist/js/node/analyze/utils.js +40 -18
- package/dist/js/node/builder/builderPlugins/compatModern.js +36 -27
- package/dist/js/node/builder/index.js +42 -55
- package/dist/js/node/builder/loaders/routerLoader.js +5 -3
- package/dist/js/node/builder/loaders/serverModuleLoader.js +5 -3
- package/dist/js/node/builder/share.js +11 -7
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +7 -3
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +7 -3
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +12 -8
- package/dist/js/node/commands/build.js +30 -28
- package/dist/js/node/commands/deploy.js +9 -5
- package/dist/js/node/commands/dev.js +39 -40
- package/dist/js/node/commands/index.js +5 -5
- package/dist/js/node/commands/inspect.js +10 -6
- package/dist/js/node/commands/{start.js → serve.js} +16 -10
- package/dist/js/node/config/default.js +44 -64
- package/dist/js/node/config/index.js +10 -3
- package/dist/js/node/config/initial/createHtmlConfig.js +7 -3
- package/dist/js/node/config/initial/createOutputConfig.js +8 -6
- package/dist/js/node/config/initial/createSourceConfig.js +12 -4
- package/dist/js/node/config/initial/createToolsConfig.js +7 -3
- package/dist/js/node/config/initial/index.js +9 -3
- package/dist/js/node/config/initial/inits.js +33 -22
- package/dist/js/node/config/initial/transformNormalizedConfig.js +12 -4
- package/dist/js/node/defineConfig.js +25 -22
- package/dist/js/node/exports/server.js +7 -3
- package/dist/js/node/hooks.js +13 -4
- package/dist/js/node/index.js +135 -111
- package/dist/js/node/initialize/index.js +33 -32
- package/dist/js/node/locale/en.js +8 -4
- package/dist/js/node/locale/index.js +8 -3
- package/dist/js/node/locale/zh.js +8 -4
- package/dist/js/node/schema/Schema.js +7 -3
- package/dist/js/node/schema/index.js +14 -11
- package/dist/js/node/schema/legacy.js +7 -6
- package/dist/js/node/types/config/deploy.js +15 -0
- package/dist/js/node/types/config/dev.js +15 -0
- package/dist/js/node/types/config/experiments.js +15 -0
- package/dist/js/node/types/config/html.js +15 -0
- package/dist/js/node/types/config/index.js +3 -3
- package/dist/js/node/types/config/output.js +15 -0
- package/dist/js/node/types/config/performance.js +15 -0
- package/dist/js/node/types/config/security.js +15 -0
- package/dist/js/node/types/config/source.js +15 -0
- package/dist/js/node/types/config/tools.js +15 -0
- package/dist/js/node/types/hooks.js +15 -0
- package/dist/js/node/types/index.js +5 -5
- package/dist/js/node/types/legacyConfig/deploy.js +15 -0
- package/dist/js/node/types/legacyConfig/dev.js +15 -0
- package/dist/js/node/types/legacyConfig/index.js +15 -0
- package/dist/js/node/types/legacyConfig/output.js +15 -0
- package/dist/js/node/types/legacyConfig/source.js +15 -0
- package/dist/js/node/types/legacyConfig/tools.js +15 -0
- package/dist/js/node/utils/commands.js +14 -4
- package/dist/js/node/utils/config.js +35 -30
- package/dist/js/node/utils/createFileWatcher.js +15 -10
- package/dist/js/node/utils/createServer.js +35 -29
- package/dist/js/node/utils/env.js +38 -0
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +10 -6
- package/dist/js/node/utils/language.js +7 -3
- package/dist/js/node/utils/printInstructions.js +10 -6
- package/dist/js/node/utils/restart.js +11 -7
- package/dist/js/node/utils/routes.js +11 -7
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +13 -1
- package/dist/js/treeshaking/analyze/generateCode.js +14 -17
- package/dist/js/treeshaking/analyze/getBundleEntry.js +5 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +9 -6
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +11 -3
- package/dist/js/treeshaking/analyze/index.js +110 -7
- package/dist/js/treeshaking/analyze/nestedRoutes.js +30 -23
- package/dist/js/treeshaking/analyze/templates.js +13 -8
- package/dist/js/treeshaking/analyze/utils.js +15 -4
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -1
- package/dist/js/treeshaking/builder/index.js +13 -20
- package/dist/js/treeshaking/builder/share.js +1 -4
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +3 -1
- package/dist/js/treeshaking/commands/dev.js +19 -24
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/{start.js → serve.js} +10 -3
- package/dist/js/treeshaking/config/default.js +53 -56
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +1 -3
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +5 -1
- package/dist/js/treeshaking/config/initial/inits.js +7 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +5 -1
- package/dist/js/treeshaking/hooks.js +6 -1
- package/dist/js/treeshaking/index.js +349 -132
- package/dist/js/treeshaking/initialize/index.js +6 -5
- package/dist/js/treeshaking/locale/en.js +1 -1
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/schema/index.js +11 -12
- package/dist/js/treeshaking/schema/legacy.js +1 -4
- package/dist/js/treeshaking/utils/commands.js +5 -1
- package/dist/js/treeshaking/utils/env.js +13 -0
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/constants.d.ts +13 -1
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +3 -3
- package/dist/types/builder/index.d.ts +2 -2
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/locale/en.d.ts +1 -1
- package/dist/types/locale/index.d.ts +2 -2
- package/dist/types/locale/zh.d.ts +1 -1
- package/dist/types/schema/Schema.d.ts +1 -1
- package/dist/types/types/config/deploy.d.ts +1 -1
- package/dist/types/types/config/dev.d.ts +4 -4
- package/dist/types/types/config/experiments.d.ts +3 -3
- package/dist/types/types/config/html.d.ts +3 -3
- package/dist/types/types/config/index.d.ts +6 -3
- package/dist/types/types/config/output.d.ts +6 -6
- package/dist/types/types/config/performance.d.ts +3 -3
- package/dist/types/types/config/security.d.ts +3 -3
- package/dist/types/types/config/source.d.ts +6 -5
- package/dist/types/types/config/tools.d.ts +3 -3
- package/dist/types/types/hooks.d.ts +9 -1
- package/dist/types/types/index.d.ts +6 -6
- package/dist/types/types/legacyConfig/deploy.d.ts +1 -1
- package/dist/types/types/legacyConfig/dev.d.ts +2 -2
- package/dist/types/types/legacyConfig/index.d.ts +1 -1
- package/dist/types/types/legacyConfig/output.d.ts +2 -2
- package/dist/types/types/legacyConfig/source.d.ts +1 -2
- package/dist/types/types/legacyConfig/tools.d.ts +2 -2
- package/dist/types/utils/commands.d.ts +2 -1
- package/dist/types/utils/env.d.ts +2 -0
- package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
- package/dist/types/utils/types.d.ts +5 -5
- package/package.json +27 -24
|
@@ -42,6 +42,7 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
42
42
|
return config;
|
|
43
43
|
});
|
|
44
44
|
api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
|
|
45
|
+
var _a;
|
|
45
46
|
const builderNormalizedConfig = api.getNormalizedConfig();
|
|
46
47
|
if (target === "node") {
|
|
47
48
|
chain.name("server");
|
|
@@ -76,10 +77,10 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
76
77
|
chain
|
|
77
78
|
);
|
|
78
79
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
79
|
-
var
|
|
80
|
+
var _a2;
|
|
80
81
|
return [
|
|
81
82
|
{
|
|
82
|
-
patterns: [...((
|
|
83
|
+
patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
|
|
83
84
|
}
|
|
84
85
|
];
|
|
85
86
|
});
|
|
@@ -88,7 +89,8 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
88
89
|
const existNestedRoutes = entrypoints.some(
|
|
89
90
|
(entrypoint) => entrypoint.nestedRoutesEntry
|
|
90
91
|
);
|
|
91
|
-
const
|
|
92
|
+
const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
|
|
93
|
+
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
92
94
|
if (existNestedRoutes || routerManifest) {
|
|
93
95
|
chain.plugin("route-plugin").use(RouterPlugin);
|
|
94
96
|
}
|
|
@@ -98,8 +100,8 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
|
|
|
98
100
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
99
101
|
}
|
|
100
102
|
function isHtmlEnabled(config, target2) {
|
|
101
|
-
var
|
|
102
|
-
return ((
|
|
103
|
+
var _a2;
|
|
104
|
+
return ((_a2 = config.tools) == null ? void 0 : _a2.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
|
|
103
105
|
}
|
|
104
106
|
});
|
|
105
107
|
if (options) {
|
|
@@ -142,6 +144,11 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
142
144
|
if (isProd2 && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
|
|
143
145
|
return;
|
|
144
146
|
}
|
|
147
|
+
if (typeof entries === "undefined") {
|
|
148
|
+
throw new Error(
|
|
149
|
+
"No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
145
152
|
const entryNames = Object.keys(entries);
|
|
146
153
|
if (isProd2 && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
|
|
147
154
|
return;
|
|
@@ -43,19 +43,25 @@ import {
|
|
|
43
43
|
import {
|
|
44
44
|
builderWebpackProvider
|
|
45
45
|
} from "@modern-js/builder-webpack-provider";
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
applyOptionsChain,
|
|
48
|
+
isProd,
|
|
49
|
+
isSSR,
|
|
50
|
+
isUseSSRBundle
|
|
51
|
+
} from "@modern-js/utils";
|
|
47
52
|
import {
|
|
48
53
|
PluginCompatModern
|
|
49
54
|
} from "./builderPlugins/compatModern";
|
|
50
55
|
import { createCopyPattern } from "./share";
|
|
51
56
|
function getBuilderTargets(normalizedConfig) {
|
|
52
57
|
const targets = ["web"];
|
|
53
|
-
|
|
58
|
+
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
|
59
|
+
if (useNodeTarget) {
|
|
54
60
|
targets.push("node");
|
|
55
61
|
}
|
|
56
62
|
return targets;
|
|
57
63
|
}
|
|
58
|
-
function
|
|
64
|
+
function createBuilderForModern(_0) {
|
|
59
65
|
return __async(this, arguments, function* ({
|
|
60
66
|
normalizedConfig,
|
|
61
67
|
appContext,
|
|
@@ -88,19 +94,11 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
88
94
|
htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
|
|
89
95
|
}
|
|
90
96
|
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
91
|
-
source: __spreadProps(__spreadValues({}, normalizedConfig.source), {
|
|
92
|
-
resolveExtensionPrefix: ".web"
|
|
93
|
-
}),
|
|
94
97
|
output,
|
|
95
|
-
dev: {
|
|
96
|
-
port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
html: htmlConfig,
|
|
101
|
-
performance: __spreadProps(__spreadValues({}, normalizedConfig.performance), {
|
|
102
|
-
removeMomentLocale: true
|
|
103
|
-
})
|
|
98
|
+
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
99
|
+
port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
|
|
100
|
+
}),
|
|
101
|
+
html: htmlConfig
|
|
104
102
|
});
|
|
105
103
|
function createOutputConfig(config, appContext2) {
|
|
106
104
|
const defaultCopyPattern = createCopyPattern(appContext2, config, "upload");
|
|
@@ -156,7 +154,7 @@ function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPlugin
|
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
export {
|
|
159
|
-
|
|
157
|
+
createBuilderForModern,
|
|
160
158
|
createBuilderOptions,
|
|
161
159
|
createBuilderProviderConfig
|
|
162
160
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
3
2
|
import { removeTailSlash } from "@modern-js/utils";
|
|
4
3
|
function createCopyPattern(appContext, config, patternsType, chain) {
|
|
5
4
|
const configDir = path.resolve(
|
|
@@ -26,9 +25,10 @@ function createCopyPattern(appContext, config, patternsType, chain) {
|
|
|
26
25
|
if (!/\.html?$/.test(absoluteFrom)) {
|
|
27
26
|
return content;
|
|
28
27
|
}
|
|
29
|
-
return
|
|
30
|
-
assetPrefix
|
|
31
|
-
|
|
28
|
+
return content.toString("utf8").replace(
|
|
29
|
+
/<%=\s*assetPrefix\s*%>/g,
|
|
30
|
+
removeTailSlash(chain.output.get("publicPath"))
|
|
31
|
+
);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
} else {
|
|
@@ -91,7 +91,9 @@ class RouterPlugin {
|
|
|
91
91
|
const entryChunks = [...compilation.chunks].filter((chunk) => {
|
|
92
92
|
return entryChunkIds.includes(chunk.name);
|
|
93
93
|
});
|
|
94
|
-
const entryChunkFiles = entryChunks.map(
|
|
94
|
+
const entryChunkFiles = entryChunks.map(
|
|
95
|
+
(chunk) => [...chunk.files].find((fname) => fname.includes(".js"))
|
|
96
|
+
);
|
|
95
97
|
for (const file of entryChunkFiles) {
|
|
96
98
|
const asset = compilation.assets[file];
|
|
97
99
|
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
import { generateRoutes } from "../utils/routes";
|
|
49
49
|
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
50
50
|
import { buildServerConfig } from "../utils/config";
|
|
51
|
+
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
51
52
|
const dev = (api, options) => __async(void 0, null, function* () {
|
|
52
53
|
var _a;
|
|
53
54
|
if (options.analyze) {
|
|
@@ -64,8 +65,7 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
64
65
|
port,
|
|
65
66
|
apiOnly,
|
|
66
67
|
entrypoints,
|
|
67
|
-
serverConfigFile
|
|
68
|
-
serverInternalPlugins
|
|
68
|
+
serverConfigFile
|
|
69
69
|
} = appContext;
|
|
70
70
|
const checkedEntries = yield getSpecifiedEntries(
|
|
71
71
|
options.entry || false,
|
|
@@ -86,29 +86,27 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
yield hookRunners.beforeDev();
|
|
89
|
-
let compiler;
|
|
90
89
|
if (!appContext.builder && !apiOnly) {
|
|
91
90
|
throw new Error(
|
|
92
91
|
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
93
92
|
);
|
|
94
93
|
}
|
|
95
|
-
if (!apiOnly) {
|
|
96
|
-
compiler = yield appContext.builder.createCompiler();
|
|
97
|
-
}
|
|
98
94
|
yield generateRoutes(appContext);
|
|
95
|
+
const serverInternalPlugins = yield getServerInternalPlugins(api);
|
|
99
96
|
const serverOptions = {
|
|
100
97
|
dev: __spreadValues({
|
|
101
98
|
port,
|
|
102
99
|
https: normalizedConfig.dev.https
|
|
103
100
|
}, (_a = normalizedConfig.tools) == null ? void 0 : _a.devServer),
|
|
104
|
-
compiler: compiler || null,
|
|
105
101
|
pwd: appDirectory,
|
|
106
102
|
config: normalizedConfig,
|
|
107
103
|
serverConfigFile,
|
|
108
104
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
109
105
|
};
|
|
110
106
|
if (apiOnly) {
|
|
111
|
-
const app = yield createServer(serverOptions)
|
|
107
|
+
const app = yield createServer(__spreadProps(__spreadValues({}, serverOptions), {
|
|
108
|
+
compiler: null
|
|
109
|
+
}));
|
|
112
110
|
app.listen(port, (err) => __async(void 0, null, function* () {
|
|
113
111
|
if (err) {
|
|
114
112
|
throw err;
|
|
@@ -117,7 +115,6 @@ const dev = (api, options) => __async(void 0, null, function* () {
|
|
|
117
115
|
}));
|
|
118
116
|
} else {
|
|
119
117
|
const { server } = yield appContext.builder.startDevServer({
|
|
120
|
-
compiler,
|
|
121
118
|
printURLs: false,
|
|
122
119
|
serverOptions
|
|
123
120
|
});
|
|
@@ -22,6 +22,7 @@ import { logger, chalk, isApiOnly } from "@modern-js/utils";
|
|
|
22
22
|
import server from "@modern-js/prod-server";
|
|
23
23
|
import { printInstructions } from "../utils/printInstructions";
|
|
24
24
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
25
|
+
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
25
26
|
const start = (api) => __async(void 0, null, function* () {
|
|
26
27
|
var _a;
|
|
27
28
|
const appContext = api.useAppContext();
|
|
@@ -33,11 +34,12 @@ const start = (api) => __async(void 0, null, function* () {
|
|
|
33
34
|
appContext.appDirectory,
|
|
34
35
|
(_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
|
|
35
36
|
);
|
|
37
|
+
const serverInternalPlugins = yield getServerInternalPlugins(api);
|
|
36
38
|
const app = yield server({
|
|
37
39
|
pwd: appDirectory,
|
|
38
40
|
config: userConfig,
|
|
39
41
|
serverConfigFile,
|
|
40
|
-
internalPlugins: injectDataLoaderPlugin(
|
|
42
|
+
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
|
|
41
43
|
apiOnly
|
|
42
44
|
});
|
|
43
45
|
app.listen(port, (err) => __async(void 0, null, function* () {
|
|
@@ -1,46 +1,45 @@
|
|
|
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
|
+
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
1
21
|
function createDefaultConfig(appContext) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
const source = {
|
|
22
|
+
const defaultBuilderConfig = createDefaultBuilderConfig();
|
|
23
|
+
const dev = __spreadValues({}, defaultBuilderConfig.dev);
|
|
24
|
+
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
25
|
+
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
26
|
+
disableNodePolyfill: true
|
|
27
|
+
});
|
|
28
|
+
const source = __spreadProps(__spreadValues({}, defaultBuilderConfig.source), {
|
|
9
29
|
entries: void 0,
|
|
10
30
|
enableAsyncEntry: false,
|
|
11
31
|
disableDefaultEntries: false,
|
|
12
32
|
entriesDir: "./src",
|
|
13
33
|
configDir: "./config",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
html: "html",
|
|
23
|
-
js: "static/js",
|
|
24
|
-
css: "static/css",
|
|
25
|
-
media: "static/media",
|
|
26
|
-
root: "dist"
|
|
27
|
-
},
|
|
28
|
-
copy: void 0,
|
|
29
|
-
disableCssModuleExtension: false,
|
|
30
|
-
enableCssModuleTSDeclaration: false,
|
|
31
|
-
disableMinimize: false,
|
|
32
|
-
enableInlineStyles: false,
|
|
33
|
-
enableInlineScripts: false,
|
|
34
|
-
disableSourceMap: false,
|
|
35
|
-
disableInlineRuntimeChunk: false,
|
|
36
|
-
disableFilenameHash: false,
|
|
37
|
-
enableLatestDecorators: false,
|
|
38
|
-
polyfill: "entry",
|
|
39
|
-
cssModuleLocalIdentName: void 0
|
|
40
|
-
};
|
|
41
|
-
const html = {
|
|
34
|
+
alias: {
|
|
35
|
+
[appContext.internalDirAlias]: appContext.internalDirectory,
|
|
36
|
+
[appContext.internalSrcAlias]: appContext.srcDirectory,
|
|
37
|
+
"@": appContext.srcDirectory,
|
|
38
|
+
"@shared": appContext.sharedDirectory
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const html = __spreadProps(__spreadValues({}, defaultBuilderConfig.html), {
|
|
42
42
|
title: "",
|
|
43
|
-
titleByEntries: void 0,
|
|
44
43
|
meta: {
|
|
45
44
|
charset: { charset: "utf-8" },
|
|
46
45
|
viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
|
|
@@ -50,17 +49,8 @@ function createDefaultConfig(appContext) {
|
|
|
50
49
|
imagemode: "force",
|
|
51
50
|
"wap-font-scale": "no",
|
|
52
51
|
"format-detection": "telephone=no"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
inject: "head",
|
|
56
|
-
injectByEntries: void 0,
|
|
57
|
-
mountId: "root",
|
|
58
|
-
favicon: "",
|
|
59
|
-
faviconByEntries: void 0,
|
|
60
|
-
disableHtmlFolder: false,
|
|
61
|
-
templateParameters: {},
|
|
62
|
-
templateParametersByEntries: void 0
|
|
63
|
-
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
64
54
|
const server = {
|
|
65
55
|
routes: void 0,
|
|
66
56
|
publicRoutes: void 0,
|
|
@@ -69,20 +59,6 @@ function createDefaultConfig(appContext) {
|
|
|
69
59
|
baseUrl: "/",
|
|
70
60
|
port: 8080
|
|
71
61
|
};
|
|
72
|
-
const dev = {
|
|
73
|
-
assetPrefix: false,
|
|
74
|
-
https: false
|
|
75
|
-
};
|
|
76
|
-
const tools = {
|
|
77
|
-
webpack: void 0,
|
|
78
|
-
babel: void 0,
|
|
79
|
-
postcss: void 0,
|
|
80
|
-
autoprefixer: void 0,
|
|
81
|
-
devServer: void 0,
|
|
82
|
-
tsLoader: void 0,
|
|
83
|
-
terser: void 0,
|
|
84
|
-
minifyCss: void 0
|
|
85
|
-
};
|
|
86
62
|
return {
|
|
87
63
|
source,
|
|
88
64
|
output,
|
|
@@ -91,6 +67,7 @@ function createDefaultConfig(appContext) {
|
|
|
91
67
|
html,
|
|
92
68
|
tools,
|
|
93
69
|
plugins: [],
|
|
70
|
+
builderPlugins: [],
|
|
94
71
|
runtime: {},
|
|
95
72
|
runtimeByEntries: {}
|
|
96
73
|
};
|
|
@@ -44,6 +44,7 @@ function createOutputConfig(config) {
|
|
|
44
44
|
font: dataUriLimit,
|
|
45
45
|
media: dataUriLimit
|
|
46
46
|
},
|
|
47
|
+
cssModuleLocalIdentName,
|
|
47
48
|
disableCssExtract,
|
|
48
49
|
disableCssModuleExtension,
|
|
49
50
|
disableInlineRuntimeChunk,
|
|
@@ -56,9 +57,6 @@ function createOutputConfig(config) {
|
|
|
56
57
|
polyfill,
|
|
57
58
|
disableFilenameHash: disableAssetsCache,
|
|
58
59
|
enableLatestDecorators,
|
|
59
|
-
filename: {
|
|
60
|
-
css: cssModuleLocalIdentName
|
|
61
|
-
},
|
|
62
60
|
ssg,
|
|
63
61
|
enableAssetFallback: true,
|
|
64
62
|
enableAssetManifest: true,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
globby,
|
|
26
26
|
isModernjsMonorepo
|
|
27
27
|
} from "@modern-js/utils";
|
|
28
|
+
import { getAutoInjectEnv } from "../../utils/env";
|
|
28
29
|
function initHtmlConfig(config, appContext) {
|
|
29
30
|
const ICON_EXTENSIONS = ["png", "jpg", "jpeg", "svg", "ico"];
|
|
30
31
|
config.html.appIcon = createBuilderAppIcon(config, appContext);
|
|
@@ -61,6 +62,12 @@ function initHtmlConfig(config, appContext) {
|
|
|
61
62
|
function initSourceConfig(config, appContext) {
|
|
62
63
|
config.source.include = createBuilderInclude(config, appContext);
|
|
63
64
|
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
65
|
+
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
66
|
+
function createBuilderGlobalVars(config2, appContext2) {
|
|
67
|
+
const { globalVars = {} } = config2.source;
|
|
68
|
+
const publicEnv = getAutoInjectEnv(appContext2);
|
|
69
|
+
return __spreadValues(__spreadValues({}, globalVars), publicEnv);
|
|
70
|
+
}
|
|
64
71
|
function createBuilderInclude(config2, appContext2) {
|
|
65
72
|
const { include } = config2.source;
|
|
66
73
|
const defaultInclude = [appContext2.internalDirectory];
|
|
@@ -31,11 +31,15 @@ function transformNormalizedConfig(config) {
|
|
|
31
31
|
server,
|
|
32
32
|
cliOptions,
|
|
33
33
|
testing,
|
|
34
|
+
builderPlugins: [],
|
|
34
35
|
plugins,
|
|
35
36
|
security: {},
|
|
36
37
|
_raw: {},
|
|
37
38
|
experiments: {},
|
|
38
|
-
|
|
39
|
+
autoLoadPlugins: true,
|
|
40
|
+
performance: {
|
|
41
|
+
removeMomentLocale: true
|
|
42
|
+
}
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
export {
|
package/dist/js/modern/hooks.js
CHANGED
|
@@ -14,6 +14,7 @@ const hooks = {
|
|
|
14
14
|
htmlPartials: createAsyncWaterfall(),
|
|
15
15
|
beforeGenerateRoutes: createAsyncWaterfall(),
|
|
16
16
|
addDefineTypes: createAsyncWaterfall(),
|
|
17
|
+
collectServerPlugins: createAsyncWaterfall(),
|
|
17
18
|
beforeDev: createAsyncWorkflow(),
|
|
18
19
|
afterDev: createAsyncWorkflow(),
|
|
19
20
|
beforeCreateCompiler: createAsyncWorkflow(),
|
|
@@ -25,7 +26,11 @@ const hooks = {
|
|
|
25
26
|
afterDeploy: createAsyncWorkflow(),
|
|
26
27
|
watchFiles: createParallelWorkflow(),
|
|
27
28
|
fileChange: createAsyncWorkflow(),
|
|
28
|
-
beforeRestart: createAsyncWorkflow()
|
|
29
|
+
beforeRestart: createAsyncWorkflow(),
|
|
30
|
+
registerDev: createParallelWorkflow(),
|
|
31
|
+
beforeDevTask: createParallelWorkflow(),
|
|
32
|
+
registerBuildPlatform: createParallelWorkflow(),
|
|
33
|
+
beforeBuildPlatform: createParallelWorkflow()
|
|
29
34
|
};
|
|
30
35
|
export {
|
|
31
36
|
hooks
|
package/dist/js/modern/index.js
CHANGED
|
@@ -40,6 +40,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
import path from "path";
|
|
41
41
|
import LintPlugin from "@modern-js/plugin-lint";
|
|
42
42
|
import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
|
|
43
|
+
import { castArray } from "@modern-js/utils/lodash";
|
|
43
44
|
import AnalyzePlugin from "./analyze";
|
|
44
45
|
import InitializePlugin from "./initialize";
|
|
45
46
|
import { hooks } from "./hooks";
|
|
@@ -53,6 +54,51 @@ const upgradeModel = Import.lazy(
|
|
|
53
54
|
"@modern-js/upgrade",
|
|
54
55
|
require
|
|
55
56
|
);
|
|
57
|
+
const devCommand = (program, api) => __async(void 0, null, function* () {
|
|
58
|
+
const runner = api.useHookRunners();
|
|
59
|
+
const devToolMetas = yield runner.registerDev();
|
|
60
|
+
const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).action((options) => __async(void 0, null, function* () {
|
|
61
|
+
const { dev } = yield import("./commands/dev");
|
|
62
|
+
yield dev(api, options);
|
|
63
|
+
}));
|
|
64
|
+
for (const meta of devToolMetas) {
|
|
65
|
+
if (!meta.subCommands) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (const subCmd of meta.subCommands) {
|
|
69
|
+
devProgram.command(subCmd).action((..._0) => __async(void 0, [..._0], function* (options = {}) {
|
|
70
|
+
const { appDirectory } = api.useAppContext();
|
|
71
|
+
const { isTypescript } = yield import("@modern-js/utils");
|
|
72
|
+
yield runner.beforeDevTask(meta);
|
|
73
|
+
yield meta.action(options, {
|
|
74
|
+
isTsProject: isTypescript(appDirectory)
|
|
75
|
+
});
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
81
|
+
const runner = api.useHookRunners();
|
|
82
|
+
const platformBuilders = yield runner.registerBuildPlatform();
|
|
83
|
+
const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action((options) => __async(void 0, null, function* () {
|
|
84
|
+
const { build } = yield import("./commands/build");
|
|
85
|
+
yield build(api, options);
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}));
|
|
88
|
+
for (const platformBuilder of platformBuilders) {
|
|
89
|
+
const platforms = castArray(platformBuilder.platform);
|
|
90
|
+
for (const platform of platforms) {
|
|
91
|
+
buildProgram.command(platform).action(() => __async(void 0, null, function* () {
|
|
92
|
+
const { appDirectory } = api.useAppContext();
|
|
93
|
+
const { isTypescript } = yield import("@modern-js/utils");
|
|
94
|
+
yield runner.beforeBuildPlatform(platformBuilders);
|
|
95
|
+
yield platformBuilder.build(platform, {
|
|
96
|
+
isTsProject: isTypescript(appDirectory)
|
|
97
|
+
});
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
56
102
|
var src_default = () => ({
|
|
57
103
|
name: "@modern-js/app-tools",
|
|
58
104
|
post: [
|
|
@@ -62,7 +108,7 @@ var src_default = () => ({
|
|
|
62
108
|
"@modern-js/plugin-document",
|
|
63
109
|
"@modern-js/plugin-state",
|
|
64
110
|
"@modern-js/plugin-router",
|
|
65
|
-
"@modern-js/plugin-router-
|
|
111
|
+
"@modern-js/plugin-router-v5",
|
|
66
112
|
"@modern-js/plugin-polyfill"
|
|
67
113
|
],
|
|
68
114
|
registerHook: hooks,
|
|
@@ -71,67 +117,56 @@ var src_default = () => ({
|
|
|
71
117
|
const locale = getLocaleLanguage();
|
|
72
118
|
i18n.changeLanguage({ locale });
|
|
73
119
|
return {
|
|
74
|
-
commands(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
)
|
|
119
|
-
"--output <output>",
|
|
120
|
-
i18n.t(localeKeys.command.inspect.output),
|
|
121
|
-
"/"
|
|
122
|
-
).option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option(
|
|
123
|
-
"-c --config <config>",
|
|
124
|
-
i18n.t(localeKeys.command.shared.config)
|
|
125
|
-
).action((options) => __async(this, null, function* () {
|
|
126
|
-
const { inspect } = yield import("./commands/inspect");
|
|
127
|
-
inspect(api, options);
|
|
128
|
-
}));
|
|
129
|
-
upgradeModel.defineCommand(program.command("upgrade"));
|
|
120
|
+
commands(_0) {
|
|
121
|
+
return __async(this, arguments, function* ({ program }) {
|
|
122
|
+
yield devCommand(program, api);
|
|
123
|
+
yield buildCommand(program, api);
|
|
124
|
+
program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option(
|
|
125
|
+
"-c --config <config>",
|
|
126
|
+
i18n.t(localeKeys.command.shared.config)
|
|
127
|
+
).action(() => __async(this, null, function* () {
|
|
128
|
+
const { start } = yield import("./commands/serve");
|
|
129
|
+
yield start(api);
|
|
130
|
+
}));
|
|
131
|
+
program.command("deploy").usage("[options]").option(
|
|
132
|
+
"-c --config <config>",
|
|
133
|
+
i18n.t(localeKeys.command.shared.config)
|
|
134
|
+
).description(i18n.t(localeKeys.command.deploy.describe)).action((options) => __async(this, null, function* () {
|
|
135
|
+
const { build } = yield import("./commands/build");
|
|
136
|
+
yield build(api);
|
|
137
|
+
const { deploy } = yield import("./commands/deploy");
|
|
138
|
+
yield deploy(api, options);
|
|
139
|
+
process.exit(0);
|
|
140
|
+
}));
|
|
141
|
+
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option(
|
|
142
|
+
"-c, --config <config>",
|
|
143
|
+
i18n.t(localeKeys.command.new.config)
|
|
144
|
+
).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
|
|
145
|
+
const { MWANewAction } = yield import("@modern-js/new-action");
|
|
146
|
+
yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale }));
|
|
147
|
+
}));
|
|
148
|
+
program.command("inspect").description("inspect internal webpack config").option(
|
|
149
|
+
`--env <env>`,
|
|
150
|
+
i18n.t(localeKeys.command.inspect.env),
|
|
151
|
+
"development"
|
|
152
|
+
).option(
|
|
153
|
+
"--output <output>",
|
|
154
|
+
i18n.t(localeKeys.command.inspect.output),
|
|
155
|
+
"/"
|
|
156
|
+
).option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option(
|
|
157
|
+
"-c --config <config>",
|
|
158
|
+
i18n.t(localeKeys.command.shared.config)
|
|
159
|
+
).action((options) => __async(this, null, function* () {
|
|
160
|
+
const { inspect } = yield import("./commands/inspect");
|
|
161
|
+
inspect(api, options);
|
|
162
|
+
}));
|
|
163
|
+
upgradeModel.defineCommand(program.command("upgrade"));
|
|
164
|
+
});
|
|
130
165
|
},
|
|
131
166
|
prepare() {
|
|
132
167
|
return __async(this, null, function* () {
|
|
133
168
|
const command = getCommand();
|
|
134
|
-
if (command === "dev" || command === "build") {
|
|
169
|
+
if (command === "dev" || command === "start" || command === "build") {
|
|
135
170
|
const appContext = api.useAppContext();
|
|
136
171
|
yield emptyDir(appContext.distDirectory);
|
|
137
172
|
}
|
|
@@ -159,5 +194,7 @@ var src_default = () => ({
|
|
|
159
194
|
}
|
|
160
195
|
});
|
|
161
196
|
export {
|
|
162
|
-
|
|
197
|
+
buildCommand,
|
|
198
|
+
src_default as default,
|
|
199
|
+
devCommand
|
|
163
200
|
};
|