@modern-js/app-tools 2.20.0 → 2.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/bin/modern.js +0 -1
- package/dist/cjs/analyze/generateCode.js +18 -1
- package/dist/cjs/analyze/getBundleEntry.js +1 -1
- package/dist/cjs/analyze/index.js +4 -2
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -14
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -15
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -2
- package/dist/cjs/index.js +14 -9
- package/dist/esm/analyze/generateCode.js +8 -3
- package/dist/esm/analyze/getBundleEntry.js +1 -1
- package/dist/esm/analyze/index.js +6 -2
- package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -14
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +2 -6
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -3
- package/dist/esm/index.js +17 -13
- package/dist/esm-node/analyze/generateCode.js +19 -2
- package/dist/esm-node/analyze/getBundleEntry.js +1 -1
- package/dist/esm-node/analyze/index.js +4 -2
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +1 -14
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -6
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -3
- package/dist/esm-node/index.js +14 -9
- package/dist/types/analyze/index.d.ts +0 -2
- package/dist/types/builder/builder-rspack/index.d.ts +1 -1
- package/dist/types/builder/builder-webpack/adapterModern.d.ts +0 -1
- package/dist/types/builder/generator/index.d.ts +1 -2
- package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +2 -3
- package/dist/types/defineConfig.d.ts +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/initialize/index.d.ts +0 -2
- package/dist/types/types/config/index.d.ts +2 -2
- package/dist/types/types/config/security.d.ts +2 -0
- package/dist/types/types/config/source.d.ts +0 -1
- package/dist/types/types/config/tools.d.ts +0 -2
- package/dist/types/types/hooks.d.ts +3 -1
- package/dist/types/types/legacyConfig/dev.d.ts +0 -1
- package/dist/types/types/legacyConfig/output.d.ts +0 -1
- package/dist/types/types/legacyConfig/source.d.ts +0 -1
- package/dist/types/types/legacyConfig/tools.d.ts +0 -1
- package/dist/types/utils/config.d.ts +0 -1
- package/dist/types/utils/getSelectedEntries.d.ts +0 -1
- package/package.json +28 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.21.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [78e3ac8]
|
|
8
|
+
- Updated dependencies [19b3b64]
|
|
9
|
+
- Updated dependencies [8e9f8c8]
|
|
10
|
+
- Updated dependencies [2728724]
|
|
11
|
+
- @modern-js/prod-server@2.21.1
|
|
12
|
+
- @modern-js/builder-shared@2.21.1
|
|
13
|
+
- @modern-js/builder-plugin-esbuild@2.21.1
|
|
14
|
+
- @modern-js/server@2.21.1
|
|
15
|
+
- @modern-js/builder@2.21.1
|
|
16
|
+
- @modern-js/builder-rspack-provider@2.21.1
|
|
17
|
+
- @modern-js/builder-webpack-provider@2.21.1
|
|
18
|
+
- @modern-js/builder-plugin-node-polyfill@2.21.1
|
|
19
|
+
- @modern-js/core@2.21.1
|
|
20
|
+
- @modern-js/plugin-data-loader@2.21.1
|
|
21
|
+
- @modern-js/plugin-i18n@2.21.1
|
|
22
|
+
- @modern-js/plugin-lint@2.21.1
|
|
23
|
+
- @modern-js/new-action@2.21.1
|
|
24
|
+
- @modern-js/node-bundle-require@2.21.1
|
|
25
|
+
- @modern-js/plugin@2.21.1
|
|
26
|
+
- @modern-js/types@2.21.1
|
|
27
|
+
- @modern-js/upgrade@2.21.1
|
|
28
|
+
- @modern-js/utils@2.21.1
|
|
29
|
+
|
|
30
|
+
## 2.21.0
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 5424051: fix: the proxy should not recreated when exists
|
|
35
|
+
fix: proxy server 不应该被重新创建当存在时
|
|
36
|
+
- cfc5bda: feat: ssr mode support async entry
|
|
37
|
+
feat: ssr 模式支持异步入口
|
|
38
|
+
- df43559: fix(core): toolsType is overridden when install multiple solutions
|
|
39
|
+
|
|
40
|
+
fix(core): 修复安装多个 solutions 时 toolsType 被覆盖的问题
|
|
41
|
+
|
|
42
|
+
- 26dcf3a: chore: bump typescript to v5 in devDependencies
|
|
43
|
+
|
|
44
|
+
chore: 升级 devDependencies 中的 typescript 版本到 v5
|
|
45
|
+
|
|
46
|
+
- d6aed02: feat(app-tools): add isFirstCompile param to afterDev hook
|
|
47
|
+
|
|
48
|
+
feat(app-tools): 为 afterDev 钩子增加 isFirstCompile 参数
|
|
49
|
+
|
|
50
|
+
- 5c56949: fix: should only watch file-based routes changes
|
|
51
|
+
fix: 只有基于文件的路由(约定式路由)需要被监听变化
|
|
52
|
+
- 4274510: fix(builder): failed to disable html via htmlPlugin: false
|
|
53
|
+
|
|
54
|
+
fix(builder): 修复通过 htmlPlugin: false 无法禁用 html 的问题
|
|
55
|
+
|
|
56
|
+
- 43b4e83: feat: support security.nonce for add nonce attribute on script tag
|
|
57
|
+
feat: 支持 security.nonce 配置,为 script 标签添加 nonce 属性
|
|
58
|
+
- ad78387: chore(deps): bump babel-related dependencies to latest version
|
|
59
|
+
|
|
60
|
+
chore(deps): 升级 babel 相关依赖到最新版本
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [cfc5bda]
|
|
63
|
+
- Updated dependencies [7d2972e]
|
|
64
|
+
- Updated dependencies [df43559]
|
|
65
|
+
- Updated dependencies [7d2972e]
|
|
66
|
+
- Updated dependencies [863f8df]
|
|
67
|
+
- Updated dependencies [55d37e9]
|
|
68
|
+
- Updated dependencies [e81eeaf]
|
|
69
|
+
- Updated dependencies [26dcf3a]
|
|
70
|
+
- Updated dependencies [8a7d4d2]
|
|
71
|
+
- Updated dependencies [1ef03dc]
|
|
72
|
+
- Updated dependencies [441a579]
|
|
73
|
+
- Updated dependencies [056627f]
|
|
74
|
+
- Updated dependencies [de8f73f]
|
|
75
|
+
- Updated dependencies [8fa8566]
|
|
76
|
+
- Updated dependencies [4274510]
|
|
77
|
+
- Updated dependencies [c90ea5a]
|
|
78
|
+
- Updated dependencies [0fc15ca]
|
|
79
|
+
- Updated dependencies [43b4e83]
|
|
80
|
+
- Updated dependencies [ad78387]
|
|
81
|
+
- @modern-js/prod-server@2.21.0
|
|
82
|
+
- @modern-js/builder-rspack-provider@2.21.0
|
|
83
|
+
- @modern-js/core@2.21.0
|
|
84
|
+
- @modern-js/builder-shared@2.21.0
|
|
85
|
+
- @modern-js/builder@2.21.0
|
|
86
|
+
- @modern-js/plugin-data-loader@2.21.0
|
|
87
|
+
- @modern-js/utils@2.21.0
|
|
88
|
+
- @modern-js/builder-webpack-provider@2.21.0
|
|
89
|
+
- @modern-js/builder-plugin-node-polyfill@2.21.0
|
|
90
|
+
- @modern-js/node-bundle-require@2.21.0
|
|
91
|
+
- @modern-js/builder-plugin-esbuild@2.21.0
|
|
92
|
+
- @modern-js/new-action@2.21.0
|
|
93
|
+
- @modern-js/plugin-i18n@2.21.0
|
|
94
|
+
- @modern-js/plugin-lint@2.21.0
|
|
95
|
+
- @modern-js/upgrade@2.21.0
|
|
96
|
+
- @modern-js/plugin@2.21.0
|
|
97
|
+
- @modern-js/server@2.21.0
|
|
98
|
+
- @modern-js/types@2.21.0
|
|
99
|
+
|
|
3
100
|
## 2.20.0
|
|
4
101
|
|
|
5
102
|
### Minor Changes
|
package/bin/modern.js
CHANGED
|
@@ -177,9 +177,26 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
177
177
|
const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
|
|
178
178
|
entrypoint.entry = entryFile;
|
|
179
179
|
if (config.source.enableAsyncEntry) {
|
|
180
|
+
let rawAsyncEntryCode = `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`;
|
|
181
|
+
const ssr = (0, _utils.getEntryOptions)(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
182
|
+
if (ssr) {
|
|
183
|
+
rawAsyncEntryCode = `
|
|
184
|
+
export const ${_utils.SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
|
|
185
|
+
let entry = await ${rawAsyncEntryCode};
|
|
186
|
+
if (entry.default instanceof Promise){
|
|
187
|
+
entry = await entry.default;
|
|
188
|
+
return entry.default.${_utils.SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
|
|
189
|
+
}
|
|
190
|
+
return entry.${_utils.SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
|
|
191
|
+
};
|
|
192
|
+
if(typeof window!=='undefined'){
|
|
193
|
+
${rawAsyncEntryCode}
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
180
197
|
const { code: asyncEntryCode } = await hookRunners.modifyAsyncEntry({
|
|
181
198
|
entrypoint,
|
|
182
|
-
code:
|
|
199
|
+
code: rawAsyncEntryCode
|
|
183
200
|
});
|
|
184
201
|
_utils.fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
185
202
|
const bootstrapFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
@@ -51,7 +51,7 @@ const getBundleEntry = (appContext, config) => {
|
|
|
51
51
|
customBootstrap: value.customBootstrap && (0, _utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
|
|
52
52
|
fileSystemRoutes: _utils.fs.statSync((0, _utils.ensureAbsolutePath)(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
53
53
|
};
|
|
54
|
-
if (entrypoint.fileSystemRoutes && (0, _utils.isRouterV5)(config)) {
|
|
54
|
+
if (entrypoint.fileSystemRoutes && !(0, _utils.isRouterV5)(config)) {
|
|
55
55
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
56
56
|
}
|
|
57
57
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -74,7 +74,7 @@ const _default = ({ bundler }) => {
|
|
|
74
74
|
};
|
|
75
75
|
api.setAppContext(appContext);
|
|
76
76
|
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
77
|
-
pagesDir = entrypoints.map((point) => point.entry).filter(
|
|
77
|
+
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !_path.extname(entry)).concat(nestedRouteEntries);
|
|
78
78
|
originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
|
|
79
79
|
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
80
80
|
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
@@ -129,7 +129,9 @@ const _default = ({ bundler }) => {
|
|
|
129
129
|
async onDevCompileDone({ isFirstCompile }) {
|
|
130
130
|
const hookRunners2 = api.useHookRunners();
|
|
131
131
|
if (process.stdout.isTTY || isFirstCompile) {
|
|
132
|
-
hookRunners2.afterDev(
|
|
132
|
+
hookRunners2.afterDev({
|
|
133
|
+
isFirstCompile
|
|
134
|
+
});
|
|
133
135
|
if (isFirstCompile) {
|
|
134
136
|
(0, _printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
|
135
137
|
}
|
|
@@ -22,7 +22,7 @@ const builderPluginAdpaterCopy = (options) => {
|
|
|
22
22
|
...config.builtins || {},
|
|
23
23
|
copy: {
|
|
24
24
|
patterns: [
|
|
25
|
-
...
|
|
25
|
+
...((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || [],
|
|
26
26
|
...createConfigBuiltinCopy(options)
|
|
27
27
|
]
|
|
28
28
|
}
|
|
@@ -57,19 +57,6 @@ const builderPluginAdpaterCopy = (options) => {
|
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
-
function transformCopy(patterns) {
|
|
61
|
-
if (patterns) {
|
|
62
|
-
patterns.map((value) => {
|
|
63
|
-
if (typeof value === "string") {
|
|
64
|
-
return {
|
|
65
|
-
from: value
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
60
|
function createConfigBuiltinCopy(options) {
|
|
74
61
|
const { normalizedConfig, appContext } = options;
|
|
75
62
|
const { uploadDir, publicDir } = (0, _shared.createCopyInfo)(appContext, normalizedConfig);
|
|
@@ -2,32 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: all[name]
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
_export(exports, {
|
|
13
|
-
isHtmlEnabled: () => isHtmlEnabled,
|
|
14
|
-
builderPluginAdapterHtml: () => builderPluginAdapterHtml
|
|
5
|
+
Object.defineProperty(exports, "builderPluginAdapterHtml", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => builderPluginAdapterHtml
|
|
15
8
|
});
|
|
16
9
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
17
10
|
const _buildershared = require("@modern-js/builder-shared");
|
|
18
11
|
const _utils = require("@modern-js/utils");
|
|
19
12
|
const _lodash = require("@modern-js/utils/lodash");
|
|
20
13
|
const _bundlerPlugins = require("../bundlerPlugins");
|
|
21
|
-
function isHtmlEnabled(config, target) {
|
|
22
|
-
var _config_tools;
|
|
23
|
-
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
24
|
-
}
|
|
25
14
|
const builderPluginAdapterHtml = (options) => ({
|
|
26
15
|
name: "builder-plugin-adapter-modern-html",
|
|
27
16
|
setup(api) {
|
|
28
17
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
|
|
29
18
|
const builderConfig = api.getNormalizedConfig();
|
|
30
|
-
if (
|
|
19
|
+
if (!(0, _buildershared.isHtmlDisabled)(builderConfig, target)) {
|
|
31
20
|
applyBottomHtmlPlugin({
|
|
32
21
|
api,
|
|
33
22
|
options,
|
|
@@ -12,7 +12,6 @@ const _buildershared = require("@modern-js/builder-shared");
|
|
|
12
12
|
const _utils = require("@modern-js/utils");
|
|
13
13
|
const _bundlerPlugins = require("../bundlerPlugins");
|
|
14
14
|
const _utils1 = require("../../../analyze/utils");
|
|
15
|
-
const _adapterHtml = require("./adapterHtml");
|
|
16
15
|
const builderPluginAdapterSSR = (options) => ({
|
|
17
16
|
name: "builder-plugin-adapter-modern-ssr",
|
|
18
17
|
setup(api) {
|
|
@@ -45,7 +44,7 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
45
44
|
appNormalizedConfig: normalizedConfig2
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
|
-
if ((0,
|
|
47
|
+
if (!(0, _buildershared.isHtmlDisabled)(builderConfig, target)) {
|
|
49
48
|
applyAsyncChunkHtmlPlugin({
|
|
50
49
|
chain,
|
|
51
50
|
modernConfig: options.normalizedConfig,
|
package/dist/cjs/index.js
CHANGED
|
@@ -103,6 +103,11 @@ const _default = (options = {
|
|
|
103
103
|
(0, _pluginlint.default)()
|
|
104
104
|
],
|
|
105
105
|
setup: (api) => {
|
|
106
|
+
const appContext = api.useAppContext();
|
|
107
|
+
api.setAppContext({
|
|
108
|
+
...appContext,
|
|
109
|
+
toolsType: "app-tools"
|
|
110
|
+
});
|
|
106
111
|
const locale = (0, _languagedetector.getLocaleLanguage)();
|
|
107
112
|
_locale.i18n.changeLanguage({
|
|
108
113
|
locale
|
|
@@ -111,11 +116,11 @@ const _default = (options = {
|
|
|
111
116
|
async beforeConfig() {
|
|
112
117
|
var _userConfig_output;
|
|
113
118
|
const userConfig = api.useConfigContext();
|
|
114
|
-
const
|
|
119
|
+
const appContext2 = api.useAppContext();
|
|
115
120
|
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
|
116
121
|
api.setAppContext({
|
|
117
|
-
...
|
|
118
|
-
internalDirectory: _path.default.resolve(
|
|
122
|
+
...appContext2,
|
|
123
|
+
internalDirectory: _path.default.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
|
119
124
|
});
|
|
120
125
|
}
|
|
121
126
|
},
|
|
@@ -151,21 +156,21 @@ const _default = (options = {
|
|
|
151
156
|
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
|
152
157
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
153
158
|
if (resolvedConfig.output.cleanDistPath) {
|
|
154
|
-
const
|
|
155
|
-
await (0, _utils.emptyDir)(
|
|
159
|
+
const appContext2 = api.useAppContext();
|
|
160
|
+
await (0, _utils.emptyDir)(appContext2.distDirectory);
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
},
|
|
159
164
|
async watchFiles() {
|
|
160
|
-
const
|
|
165
|
+
const appContext2 = api.useAppContext();
|
|
161
166
|
const config = api.useResolvedConfigContext();
|
|
162
|
-
return (0, _generateWatchFiles.generateWatchFiles)(
|
|
167
|
+
return (0, _generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
|
|
163
168
|
},
|
|
164
169
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
165
170
|
async fileChange(e) {
|
|
166
171
|
const { filename, eventType } = e;
|
|
167
|
-
const
|
|
168
|
-
const { appDirectory, srcDirectory } =
|
|
172
|
+
const appContext2 = api.useAppContext();
|
|
173
|
+
const { appDirectory, srcDirectory } = appContext2;
|
|
169
174
|
const absolutePath = _path.default.resolve(appDirectory, filename);
|
|
170
175
|
if (!absolutePath.includes(srcDirectory) && (eventType === "change" || eventType === "unlink")) {
|
|
171
176
|
const { closeServer } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./utils/createServer")));
|
|
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
5
|
+
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
|
|
6
6
|
import * as templates from "./templates";
|
|
7
7
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
8
8
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
@@ -100,7 +100,7 @@ export var generateCode = function() {
|
|
|
100
100
|
}
|
|
101
101
|
function _generateEntryCode() {
|
|
102
102
|
_generateEntryCode = _async_to_generator(function(entrypoint) {
|
|
103
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, _ref2, importStatements, plugins, _ref1, renderFunction, exportStatement, code2, entryFile, _ref22, asyncEntryCode, bootstrapFile;
|
|
103
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, _ref2, importStatements, plugins, _ref1, renderFunction, exportStatement, code2, entryFile, rawAsyncEntryCode, ssr1, _ref22, asyncEntryCode, bootstrapFile;
|
|
104
104
|
return _ts_generator(this, function(_state) {
|
|
105
105
|
switch (_state.label) {
|
|
106
106
|
case 0:
|
|
@@ -293,11 +293,16 @@ export var generateCode = function() {
|
|
|
293
293
|
3,
|
|
294
294
|
17
|
|
295
295
|
];
|
|
296
|
+
rawAsyncEntryCode = "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');");
|
|
297
|
+
ssr1 = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
298
|
+
if (ssr1) {
|
|
299
|
+
rawAsyncEntryCode = "\n export const ".concat(SERVER_RENDER_FUNCTION_NAME, " = async (...args) => {\n let entry = await ").concat(rawAsyncEntryCode, ";\n if (entry.default instanceof Promise){\n entry = await entry.default;\n return entry.default.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n }\n return entry.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n };\n if(typeof window!=='undefined'){\n ").concat(rawAsyncEntryCode, "\n }\n ");
|
|
300
|
+
}
|
|
296
301
|
return [
|
|
297
302
|
4,
|
|
298
303
|
hookRunners.modifyAsyncEntry({
|
|
299
304
|
entrypoint: entrypoint,
|
|
300
|
-
code:
|
|
305
|
+
code: rawAsyncEntryCode
|
|
301
306
|
})
|
|
302
307
|
];
|
|
303
308
|
case 16:
|
|
@@ -43,7 +43,7 @@ export var getBundleEntry = function(appContext, config) {
|
|
|
43
43
|
customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
44
44
|
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
45
45
|
};
|
|
46
|
-
if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
|
|
46
|
+
if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
|
|
47
47
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
48
48
|
}
|
|
49
49
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -111,7 +111,9 @@ export default function(param) {
|
|
|
111
111
|
}).filter(Boolean);
|
|
112
112
|
pagesDir = entrypoints.map(function(point) {
|
|
113
113
|
return point.entry;
|
|
114
|
-
}).filter(
|
|
114
|
+
}).filter(function(entry2) {
|
|
115
|
+
return entry2 && !path.extname(entry2);
|
|
116
|
+
}).concat(nestedRouteEntries);
|
|
115
117
|
originEntrypoints = cloneDeep(entrypoints);
|
|
116
118
|
return [
|
|
117
119
|
4,
|
|
@@ -251,7 +253,9 @@ export default function(param) {
|
|
|
251
253
|
return _ts_generator(this, function(_state2) {
|
|
252
254
|
hookRunners2 = api.useHookRunners();
|
|
253
255
|
if (process.stdout.isTTY || isFirstCompile) {
|
|
254
|
-
hookRunners2.afterDev(
|
|
256
|
+
hookRunners2.afterDev({
|
|
257
|
+
isFirstCompile: isFirstCompile
|
|
258
|
+
});
|
|
255
259
|
if (isFirstCompile) {
|
|
256
260
|
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
257
261
|
}
|
|
@@ -16,7 +16,7 @@ export var builderPluginAdpaterCopy = function(options) {
|
|
|
16
16
|
var _config_builtins, _config_builtins_copy, _config_output;
|
|
17
17
|
config.builtins = _object_spread_props(_object_spread({}, config.builtins || {}), {
|
|
18
18
|
copy: {
|
|
19
|
-
patterns: _to_consumable_array(
|
|
19
|
+
patterns: _to_consumable_array(((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || []).concat(_to_consumable_array(createConfigBuiltinCopy(options)))
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
|
@@ -144,19 +144,6 @@ export var builderPluginAdpaterCopy = function(options) {
|
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
};
|
|
147
|
-
function transformCopy(patterns) {
|
|
148
|
-
if (patterns) {
|
|
149
|
-
patterns.map(function(value) {
|
|
150
|
-
if (typeof value === "string") {
|
|
151
|
-
return {
|
|
152
|
-
from: value
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
return [];
|
|
159
|
-
}
|
|
160
147
|
function createConfigBuiltinCopy(options) {
|
|
161
148
|
var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
|
162
149
|
var _createCopyInfo = createCopyInfo(appContext, normalizedConfig), uploadDir = _createCopyInfo.uploadDir, publicDir = _createCopyInfo.publicDir;
|
|
@@ -3,14 +3,10 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
|
3
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
|
-
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
6
|
+
import { isHtmlDisabled, createVirtualModule } from "@modern-js/builder-shared";
|
|
7
7
|
import { getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
|
8
8
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
9
9
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
|
10
|
-
export function isHtmlEnabled(config, target) {
|
|
11
|
-
var _config_tools;
|
|
12
|
-
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
13
|
-
}
|
|
14
10
|
export var builderPluginAdapterHtml = function(options) {
|
|
15
11
|
return {
|
|
16
12
|
name: "builder-plugin-adapter-modern-html",
|
|
@@ -23,7 +19,7 @@ export var builderPluginAdapterHtml = function(options) {
|
|
|
23
19
|
case 0:
|
|
24
20
|
CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin;
|
|
25
21
|
builderConfig = api.getNormalizedConfig();
|
|
26
|
-
if (
|
|
22
|
+
if (!!isHtmlDisabled(builderConfig, target))
|
|
27
23
|
return [
|
|
28
24
|
3,
|
|
29
25
|
2
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import * as path from "path";
|
|
4
|
-
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
4
|
+
import { isHtmlDisabled, mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
5
5
|
import { isSSR, fs } from "@modern-js/utils";
|
|
6
6
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
7
7
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
8
|
-
import { isHtmlEnabled } from "./adapterHtml";
|
|
9
8
|
export var builderPluginAdapterSSR = function(options) {
|
|
10
9
|
return {
|
|
11
10
|
name: "builder-plugin-adapter-modern-ssr",
|
|
@@ -55,7 +54,7 @@ export var builderPluginAdapterSSR = function(options) {
|
|
|
55
54
|
appNormalizedConfig: normalizedConfig2
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
if (
|
|
57
|
+
if (!isHtmlDisabled(builderConfig, target)) {
|
|
59
58
|
applyAsyncChunkHtmlPlugin({
|
|
60
59
|
chain: chain,
|
|
61
60
|
modernConfig: options.normalizedConfig,
|
package/dist/esm/index.js
CHANGED
|
@@ -296,6 +296,10 @@ export default function() {
|
|
|
296
296
|
lintPlugin()
|
|
297
297
|
],
|
|
298
298
|
setup: function(api) {
|
|
299
|
+
var appContext = api.useAppContext();
|
|
300
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
|
301
|
+
toolsType: "app-tools"
|
|
302
|
+
}));
|
|
299
303
|
var locale = getLocaleLanguage();
|
|
300
304
|
i18n.changeLanguage({
|
|
301
305
|
locale: locale
|
|
@@ -303,13 +307,13 @@ export default function() {
|
|
|
303
307
|
return {
|
|
304
308
|
beforeConfig: function beforeConfig() {
|
|
305
309
|
return _async_to_generator(function() {
|
|
306
|
-
var _userConfig_output, userConfig,
|
|
310
|
+
var _userConfig_output, userConfig, appContext2;
|
|
307
311
|
return _ts_generator(this, function(_state) {
|
|
308
312
|
userConfig = api.useConfigContext();
|
|
309
|
-
|
|
313
|
+
appContext2 = api.useAppContext();
|
|
310
314
|
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
|
311
|
-
api.setAppContext(_object_spread_props(_object_spread({},
|
|
312
|
-
internalDirectory: path.resolve(
|
|
315
|
+
api.setAppContext(_object_spread_props(_object_spread({}, appContext2), {
|
|
316
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
|
313
317
|
}));
|
|
314
318
|
}
|
|
315
319
|
return [
|
|
@@ -463,7 +467,7 @@ export default function() {
|
|
|
463
467
|
},
|
|
464
468
|
prepare: function prepare() {
|
|
465
469
|
return _async_to_generator(function() {
|
|
466
|
-
var command, resolvedConfig,
|
|
470
|
+
var command, resolvedConfig, appContext2;
|
|
467
471
|
return _ts_generator(this, function(_state) {
|
|
468
472
|
switch (_state.label) {
|
|
469
473
|
case 0:
|
|
@@ -479,10 +483,10 @@ export default function() {
|
|
|
479
483
|
3,
|
|
480
484
|
2
|
|
481
485
|
];
|
|
482
|
-
|
|
486
|
+
appContext2 = api.useAppContext();
|
|
483
487
|
return [
|
|
484
488
|
4,
|
|
485
|
-
emptyDir(
|
|
489
|
+
emptyDir(appContext2.distDirectory)
|
|
486
490
|
];
|
|
487
491
|
case 1:
|
|
488
492
|
_state.sent();
|
|
@@ -497,13 +501,13 @@ export default function() {
|
|
|
497
501
|
},
|
|
498
502
|
watchFiles: function watchFiles() {
|
|
499
503
|
return _async_to_generator(function() {
|
|
500
|
-
var
|
|
504
|
+
var appContext2, config;
|
|
501
505
|
return _ts_generator(this, function(_state) {
|
|
502
|
-
|
|
506
|
+
appContext2 = api.useAppContext();
|
|
503
507
|
config = api.useResolvedConfigContext();
|
|
504
508
|
return [
|
|
505
509
|
2,
|
|
506
|
-
generateWatchFiles(
|
|
510
|
+
generateWatchFiles(appContext2, config.source.configDir)
|
|
507
511
|
];
|
|
508
512
|
});
|
|
509
513
|
})();
|
|
@@ -512,13 +516,13 @@ export default function() {
|
|
|
512
516
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
513
517
|
function fileChange(e) {
|
|
514
518
|
return _async_to_generator(function() {
|
|
515
|
-
var filename, eventType,
|
|
519
|
+
var filename, eventType, appContext2, appDirectory, srcDirectory, absolutePath, closeServer;
|
|
516
520
|
return _ts_generator(this, function(_state) {
|
|
517
521
|
switch (_state.label) {
|
|
518
522
|
case 0:
|
|
519
523
|
filename = e.filename, eventType = e.eventType;
|
|
520
|
-
|
|
521
|
-
appDirectory =
|
|
524
|
+
appContext2 = api.useAppContext();
|
|
525
|
+
appDirectory = appContext2.appDirectory, srcDirectory = appContext2.srcDirectory;
|
|
522
526
|
absolutePath = path.resolve(appDirectory, filename);
|
|
523
527
|
if (!(!absolutePath.includes(srcDirectory) && (eventType === "change" || eventType === "unlink")))
|
|
524
528
|
return [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
2
|
+
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
|
|
3
3
|
import * as templates from "./templates";
|
|
4
4
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
5
5
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
@@ -160,9 +160,26 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
160
160
|
const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
161
161
|
entrypoint.entry = entryFile;
|
|
162
162
|
if (config.source.enableAsyncEntry) {
|
|
163
|
+
let rawAsyncEntryCode = `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`;
|
|
164
|
+
const ssr = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
165
|
+
if (ssr) {
|
|
166
|
+
rawAsyncEntryCode = `
|
|
167
|
+
export const ${SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
|
|
168
|
+
let entry = await ${rawAsyncEntryCode};
|
|
169
|
+
if (entry.default instanceof Promise){
|
|
170
|
+
entry = await entry.default;
|
|
171
|
+
return entry.default.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
|
|
172
|
+
}
|
|
173
|
+
return entry.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
|
|
174
|
+
};
|
|
175
|
+
if(typeof window!=='undefined'){
|
|
176
|
+
${rawAsyncEntryCode}
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
163
180
|
const { code: asyncEntryCode } = await hookRunners.modifyAsyncEntry({
|
|
164
181
|
entrypoint,
|
|
165
|
-
code:
|
|
182
|
+
code: rawAsyncEntryCode
|
|
166
183
|
});
|
|
167
184
|
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
168
185
|
const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
@@ -42,7 +42,7 @@ export const getBundleEntry = (appContext, config) => {
|
|
|
42
42
|
customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
|
43
43
|
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
|
|
44
44
|
};
|
|
45
|
-
if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
|
|
45
|
+
if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
|
|
46
46
|
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
47
47
|
}
|
|
48
48
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
@@ -65,7 +65,7 @@ export default ({ bundler }) => {
|
|
|
65
65
|
};
|
|
66
66
|
api.setAppContext(appContext);
|
|
67
67
|
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
68
|
-
pagesDir = entrypoints.map((point) => point.entry).filter(
|
|
68
|
+
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
|
69
69
|
originEntrypoints = cloneDeep(entrypoints);
|
|
70
70
|
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
71
71
|
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
@@ -120,7 +120,9 @@ export default ({ bundler }) => {
|
|
|
120
120
|
async onDevCompileDone({ isFirstCompile }) {
|
|
121
121
|
const hookRunners2 = api.useHookRunners();
|
|
122
122
|
if (process.stdout.isTTY || isFirstCompile) {
|
|
123
|
-
hookRunners2.afterDev(
|
|
123
|
+
hookRunners2.afterDev({
|
|
124
|
+
isFirstCompile
|
|
125
|
+
});
|
|
124
126
|
if (isFirstCompile) {
|
|
125
127
|
printInstructions(hookRunners2, appContext, normalizedConfig);
|
|
126
128
|
}
|
|
@@ -13,7 +13,7 @@ export const builderPluginAdpaterCopy = (options) => {
|
|
|
13
13
|
...config.builtins || {},
|
|
14
14
|
copy: {
|
|
15
15
|
patterns: [
|
|
16
|
-
...
|
|
16
|
+
...((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || [],
|
|
17
17
|
...createConfigBuiltinCopy(options)
|
|
18
18
|
]
|
|
19
19
|
}
|
|
@@ -48,19 +48,6 @@ export const builderPluginAdpaterCopy = (options) => {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
-
function transformCopy(patterns) {
|
|
52
|
-
if (patterns) {
|
|
53
|
-
patterns.map((value) => {
|
|
54
|
-
if (typeof value === "string") {
|
|
55
|
-
return {
|
|
56
|
-
from: value
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
51
|
function createConfigBuiltinCopy(options) {
|
|
65
52
|
const { normalizedConfig, appContext } = options;
|
|
66
53
|
const { uploadDir, publicDir } = createCopyInfo(appContext, normalizedConfig);
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
1
|
+
import { isHtmlDisabled, createVirtualModule } from "@modern-js/builder-shared";
|
|
2
2
|
import { getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
|
3
3
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
4
4
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
|
5
|
-
export function isHtmlEnabled(config, target) {
|
|
6
|
-
var _config_tools;
|
|
7
|
-
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
8
|
-
}
|
|
9
5
|
export const builderPluginAdapterHtml = (options) => ({
|
|
10
6
|
name: "builder-plugin-adapter-modern-html",
|
|
11
7
|
setup(api) {
|
|
12
8
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
|
|
13
9
|
const builderConfig = api.getNormalizedConfig();
|
|
14
|
-
if (
|
|
10
|
+
if (!isHtmlDisabled(builderConfig, target)) {
|
|
15
11
|
applyBottomHtmlPlugin({
|
|
16
12
|
api,
|
|
17
13
|
options,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
2
|
+
import { isHtmlDisabled, mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
3
3
|
import { isSSR, fs } from "@modern-js/utils";
|
|
4
4
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
5
5
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
6
|
-
import { isHtmlEnabled } from "./adapterHtml";
|
|
7
6
|
export const builderPluginAdapterSSR = (options) => ({
|
|
8
7
|
name: "builder-plugin-adapter-modern-ssr",
|
|
9
8
|
setup(api) {
|
|
@@ -36,7 +35,7 @@ export const builderPluginAdapterSSR = (options) => ({
|
|
|
36
35
|
appNormalizedConfig: normalizedConfig2
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
if (
|
|
38
|
+
if (!isHtmlDisabled(builderConfig, target)) {
|
|
40
39
|
applyAsyncChunkHtmlPlugin({
|
|
41
40
|
chain,
|
|
42
41
|
modernConfig: options.normalizedConfig,
|
package/dist/esm-node/index.js
CHANGED
|
@@ -83,6 +83,11 @@ export default (options = {
|
|
|
83
83
|
lintPlugin()
|
|
84
84
|
],
|
|
85
85
|
setup: (api) => {
|
|
86
|
+
const appContext = api.useAppContext();
|
|
87
|
+
api.setAppContext({
|
|
88
|
+
...appContext,
|
|
89
|
+
toolsType: "app-tools"
|
|
90
|
+
});
|
|
86
91
|
const locale = getLocaleLanguage();
|
|
87
92
|
i18n.changeLanguage({
|
|
88
93
|
locale
|
|
@@ -91,11 +96,11 @@ export default (options = {
|
|
|
91
96
|
async beforeConfig() {
|
|
92
97
|
var _userConfig_output;
|
|
93
98
|
const userConfig = api.useConfigContext();
|
|
94
|
-
const
|
|
99
|
+
const appContext2 = api.useAppContext();
|
|
95
100
|
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
|
96
101
|
api.setAppContext({
|
|
97
|
-
...
|
|
98
|
-
internalDirectory: path.resolve(
|
|
102
|
+
...appContext2,
|
|
103
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
|
99
104
|
});
|
|
100
105
|
}
|
|
101
106
|
},
|
|
@@ -131,21 +136,21 @@ export default (options = {
|
|
|
131
136
|
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
|
132
137
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
133
138
|
if (resolvedConfig.output.cleanDistPath) {
|
|
134
|
-
const
|
|
135
|
-
await emptyDir(
|
|
139
|
+
const appContext2 = api.useAppContext();
|
|
140
|
+
await emptyDir(appContext2.distDirectory);
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
},
|
|
139
144
|
async watchFiles() {
|
|
140
|
-
const
|
|
145
|
+
const appContext2 = api.useAppContext();
|
|
141
146
|
const config = api.useResolvedConfigContext();
|
|
142
|
-
return generateWatchFiles(
|
|
147
|
+
return generateWatchFiles(appContext2, config.source.configDir);
|
|
143
148
|
},
|
|
144
149
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
145
150
|
async fileChange(e) {
|
|
146
151
|
const { filename, eventType } = e;
|
|
147
|
-
const
|
|
148
|
-
const { appDirectory, srcDirectory } =
|
|
152
|
+
const appContext2 = api.useAppContext();
|
|
153
|
+
const { appDirectory, srcDirectory } = appContext2;
|
|
149
154
|
const absolutePath = path.resolve(appDirectory, filename);
|
|
150
155
|
if (!absolutePath.includes(srcDirectory) && (eventType === "change" || eventType === "unlink")) {
|
|
151
156
|
const { closeServer } = await import("./utils/createServer");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { BuilderOptions } from '../shared';
|
|
2
|
-
export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<import("@modern-js/builder-shared").BuilderInstance<import("@modern-js/builder-shared").BuilderProvider
|
|
2
|
+
export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<import("@modern-js/builder-shared").BuilderInstance<import("@modern-js/builder-shared").BuilderProvider>>;
|
|
@@ -10,8 +10,7 @@ export type GenerateProvider = (c: {
|
|
|
10
10
|
* @param utils - ModifyBuilderConfig, ModifyBuilderInstance
|
|
11
11
|
* @returns BuilderInstance
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
export declare function generateBuilder<B extends Bundler>(options: BuilderOptions<B>, generateProvider: GenerateProvider, utils?: {
|
|
15
14
|
modifyBuilderConfig?: ModifyBuilderConfig<B>;
|
|
16
15
|
modifyBuilderInstance?: ModifyBuilderInstance;
|
|
17
|
-
}): Promise<BuilderInstance<BuilderProvider
|
|
16
|
+
}): Promise<BuilderInstance<BuilderProvider>>;
|
|
@@ -3,5 +3,4 @@ import type { BuilderOptions, BuilderPluginAPI } from '../types';
|
|
|
3
3
|
import type { Bundler } from '../../../types';
|
|
4
4
|
export declare const builderPluginAdapterBasic: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
|
|
5
5
|
/** register builder hooks callback */
|
|
6
|
-
|
|
7
6
|
export declare function applyCallbacks<B extends Bundler>(api: BuilderPluginAPI, options: BuilderOptions<B>): void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { BuilderPlugin
|
|
1
|
+
import { BuilderPlugin } from '@modern-js/builder-shared';
|
|
2
2
|
import { Bundler } from '../../../types';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function isHtmlEnabled(config: BuilderNormalizedConfig, target: BuilderTarget): boolean;
|
|
3
|
+
import type { BuilderOptions, BuilderPluginAPI } from '../types';
|
|
5
4
|
export declare const builderPluginAdapterHtml: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,7 +11,5 @@ export type AppToolsOptions = {
|
|
|
11
11
|
/** Specify the use what kind of bundler to compiler, default: `webpack` */
|
|
12
12
|
bundler?: 'experimental-rspack' | 'webpack';
|
|
13
13
|
};
|
|
14
|
-
|
|
15
14
|
declare const _default: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
|
|
16
|
-
|
|
17
15
|
export default _default;
|
|
@@ -5,7 +5,7 @@ import type { RsSourceUserConfig, SharedSourceConfig, SourceUserConfig } from '.
|
|
|
5
5
|
import type { DevUserConfig } from './dev';
|
|
6
6
|
import type { RsToolsUserConfig, SharedToolsConfig, ToolsUserConfig } from './tools';
|
|
7
7
|
import type { HtmlUserConfig, RsHtmlUserConfig, SharedHtmlConfig } from './html';
|
|
8
|
-
import type { SecurityUserConfig } from './security';
|
|
8
|
+
import type { RsSecurityConfig, SecurityUserConfig } from './security';
|
|
9
9
|
import type { DeployUserConfig } from './deploy';
|
|
10
10
|
import type { ExperimentsUserConfig } from './experiments';
|
|
11
11
|
import type { PerformanceUserConfig, RsPerformanceConfig, SharedPerformanceConfig } from './performance';
|
|
@@ -25,7 +25,6 @@ export type SharedUserConfig = {
|
|
|
25
25
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
26
26
|
* @requires `bff` plugin
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
28
|
bff?: BffUserConfig;
|
|
30
29
|
dev?: DevUserConfig;
|
|
31
30
|
deploy?: DeployUserConfig;
|
|
@@ -51,6 +50,7 @@ export interface RsAppToolsUserConfig extends SharedUserConfig {
|
|
|
51
50
|
html?: RsHtmlUserConfig;
|
|
52
51
|
tools?: RsToolsUserConfig;
|
|
53
52
|
performance?: RsPerformanceConfig;
|
|
53
|
+
security?: RsSecurityConfig;
|
|
54
54
|
}
|
|
55
55
|
interface SharedNormalizedConfig<RawConfig> {
|
|
56
56
|
cliOptions?: Record<string, any>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
|
|
2
|
+
import type { BuilderConfig as RsBuilderConfig } from '@modern-js/builder-rspack-provider';
|
|
2
3
|
import { UnwrapBuilderConfig } from '../utils';
|
|
3
4
|
export type BuilderSecurityConfig = UnwrapBuilderConfig<BuilderConfig, 'security'>;
|
|
5
|
+
export type RsSecurityConfig = UnwrapBuilderConfig<RsBuilderConfig, 'security'>;
|
|
4
6
|
export type SecurityUserConfig = BuilderSecurityConfig;
|
|
@@ -21,7 +21,6 @@ export interface SharedSourceConfig extends BuilderSharedSourceConfig {
|
|
|
21
21
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
22
22
|
* @requires `tailwindcss` plugin
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
24
|
designSystem?: Record<string, any>;
|
|
26
25
|
}
|
|
27
26
|
export type SourceUserConfig = BuilderSourceConfig & SharedSourceConfig;
|
|
@@ -14,7 +14,6 @@ export type RsBuilderToolsConfig = UnwrapBuilderConfig<RsBuilderConfig, 'tools'>
|
|
|
14
14
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
15
15
|
* @requires `tailwindcss` plugin
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
export type Tailwindcss = Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
|
|
19
18
|
export interface SharedToolsConfig extends BuilderSharedToolsConfig {
|
|
20
19
|
tailwindcss?: Tailwindcss;
|
|
@@ -23,7 +22,6 @@ export interface SharedToolsConfig extends BuilderSharedToolsConfig {
|
|
|
23
22
|
* The configuration of `swc` is provided by `swc` plugin.
|
|
24
23
|
* @requires `swc` plugin
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
25
|
swc?: PluginSwcOptions;
|
|
28
26
|
}
|
|
29
27
|
export interface ToolsUserConfig extends BuilderToolsConfig, SharedToolsConfig {}
|
|
@@ -60,7 +60,9 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
|
|
|
60
60
|
plugins: Array<Record<string, string>>;
|
|
61
61
|
}>;
|
|
62
62
|
beforeDev: AsyncWorkflow<void, unknown>;
|
|
63
|
-
afterDev: AsyncWorkflow<
|
|
63
|
+
afterDev: AsyncWorkflow<{
|
|
64
|
+
isFirstCompile: boolean;
|
|
65
|
+
}, unknown>;
|
|
64
66
|
beforeCreateCompiler: AsyncWorkflow<{
|
|
65
67
|
bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
|
|
66
68
|
}, unknown>;
|
|
@@ -10,7 +10,6 @@ export type ToolsLegacyUserConfig = BuilderToolsConfig & {
|
|
|
10
10
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
11
11
|
* @requires `tailwindcss` plugin
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
|
|
15
14
|
jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
|
|
16
15
|
};
|
|
@@ -17,6 +17,5 @@ export declare const buildServerConfig: ({
|
|
|
17
17
|
*
|
|
18
18
|
* 处理循环引用的 replacer
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
|
|
22
21
|
export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: AppNormalizedConfig<'shared'>) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.21.1",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -66,46 +66,46 @@
|
|
|
66
66
|
"modern-app": "./bin/modern.js"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@babel/parser": "^7.
|
|
70
|
-
"@babel/traverse": "^7.
|
|
71
|
-
"@babel/types": "^7.
|
|
69
|
+
"@babel/parser": "^7.21.8",
|
|
70
|
+
"@babel/traverse": "^7.21.5",
|
|
71
|
+
"@babel/types": "^7.21.5",
|
|
72
72
|
"es-module-lexer": "^1.1.0",
|
|
73
73
|
"esbuild": "0.15.7",
|
|
74
74
|
"rspack-plugin-virtual-module": "0.1.0",
|
|
75
75
|
"@swc/helpers": "0.5.1",
|
|
76
|
-
"@modern-js/builder": "2.
|
|
77
|
-
"@modern-js/builder-plugin-esbuild": "2.
|
|
78
|
-
"@modern-js/builder-plugin-node-polyfill": "2.
|
|
79
|
-
"@modern-js/builder-shared": "2.
|
|
80
|
-
"@modern-js/builder-webpack-provider": "2.
|
|
81
|
-
"@modern-js/core": "2.
|
|
82
|
-
"@modern-js/new-action": "2.
|
|
83
|
-
"@modern-js/node-bundle-require": "2.
|
|
84
|
-
"@modern-js/plugin": "2.
|
|
85
|
-
"@modern-js/plugin-data-loader": "2.
|
|
86
|
-
"@modern-js/plugin-i18n": "2.
|
|
87
|
-
"@modern-js/plugin-lint": "2.
|
|
88
|
-
"@modern-js/prod-server": "2.
|
|
89
|
-
"@modern-js/server": "2.
|
|
90
|
-
"@modern-js/types": "2.
|
|
91
|
-
"@modern-js/upgrade": "2.
|
|
92
|
-
"@modern-js/utils": "2.
|
|
76
|
+
"@modern-js/builder": "2.21.1",
|
|
77
|
+
"@modern-js/builder-plugin-esbuild": "2.21.1",
|
|
78
|
+
"@modern-js/builder-plugin-node-polyfill": "2.21.1",
|
|
79
|
+
"@modern-js/builder-shared": "2.21.1",
|
|
80
|
+
"@modern-js/builder-webpack-provider": "2.21.1",
|
|
81
|
+
"@modern-js/core": "2.21.1",
|
|
82
|
+
"@modern-js/new-action": "2.21.1",
|
|
83
|
+
"@modern-js/node-bundle-require": "2.21.1",
|
|
84
|
+
"@modern-js/plugin": "2.21.1",
|
|
85
|
+
"@modern-js/plugin-data-loader": "2.21.1",
|
|
86
|
+
"@modern-js/plugin-i18n": "2.21.1",
|
|
87
|
+
"@modern-js/plugin-lint": "2.21.1",
|
|
88
|
+
"@modern-js/prod-server": "2.21.1",
|
|
89
|
+
"@modern-js/server": "2.21.1",
|
|
90
|
+
"@modern-js/types": "2.21.1",
|
|
91
|
+
"@modern-js/upgrade": "2.21.1",
|
|
92
|
+
"@modern-js/utils": "2.21.1"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@types/babel__traverse": "^7.14.2",
|
|
96
96
|
"@types/jest": "^29",
|
|
97
97
|
"@types/node": "^14",
|
|
98
98
|
"jest": "^29",
|
|
99
|
-
"typescript": "^
|
|
99
|
+
"typescript": "^5",
|
|
100
100
|
"webpack": "^5.82.1",
|
|
101
|
-
"@modern-js/builder-plugin-swc": "2.
|
|
102
|
-
"@modern-js/builder-rspack-provider": "2.
|
|
103
|
-
"@modern-js/server-core": "2.
|
|
104
|
-
"@scripts/
|
|
105
|
-
"@scripts/
|
|
101
|
+
"@modern-js/builder-plugin-swc": "2.21.1",
|
|
102
|
+
"@modern-js/builder-rspack-provider": "2.21.1",
|
|
103
|
+
"@modern-js/server-core": "2.21.1",
|
|
104
|
+
"@scripts/jest-config": "2.21.1",
|
|
105
|
+
"@scripts/build": "2.21.1"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@modern-js/builder-rspack-provider": "^2.
|
|
108
|
+
"@modern-js/builder-rspack-provider": "^2.21.1"
|
|
109
109
|
},
|
|
110
110
|
"peerDependenciesMeta": {
|
|
111
111
|
"@modern-js/builder-rspack-provider": {
|