@modern-js/app-tools 1.4.7-canary.0 → 1.4.7-canary.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/dist/js/modern/commands/build.js +6 -3
- package/dist/js/modern/commands/dev.js +8 -3
- package/dist/js/modern/utils/config.js +28 -4
- package/dist/js/node/commands/build.js +6 -2
- package/dist/js/node/commands/dev.js +8 -3
- package/dist/js/node/utils/config.js +27 -3
- package/dist/types/utils/config.d.ts +11 -1
- package/package.json +1 -1
|
@@ -12,8 +12,7 @@ import { generateRoutes } from "../utils/routes";
|
|
|
12
12
|
import { buildServerConfig, emitResolvedConfig } from "../utils/config";
|
|
13
13
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
14
14
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
15
|
-
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
16
|
-
|
|
15
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
17
16
|
export const build = async (api, options) => {
|
|
18
17
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
19
18
|
const appContext = api.useAppContext();
|
|
@@ -98,7 +97,11 @@ export const build = async (api, options) => {
|
|
|
98
97
|
} = appContext;
|
|
99
98
|
const previousFileSizes = await measureFileSizesBeforeBuild(distDirectory);
|
|
100
99
|
await emptyDir(distDirectory);
|
|
101
|
-
await buildServerConfig(
|
|
100
|
+
await buildServerConfig({
|
|
101
|
+
appDirectory,
|
|
102
|
+
distDirectory,
|
|
103
|
+
configFile: serverConfigFile
|
|
104
|
+
});
|
|
102
105
|
const buildConfigs = [];
|
|
103
106
|
buildConfigs.push({
|
|
104
107
|
type: 'legacy',
|
|
@@ -29,9 +29,14 @@ export const dev = async (api, options) => {
|
|
|
29
29
|
}));
|
|
30
30
|
appContext.checkedEntries = checkedEntries;
|
|
31
31
|
fs.emptyDirSync(distDirectory);
|
|
32
|
-
await buildServerConfig(
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
await buildServerConfig({
|
|
33
|
+
appDirectory,
|
|
34
|
+
distDirectory,
|
|
35
|
+
configFile: serverConfigFile,
|
|
36
|
+
options: {
|
|
37
|
+
esbuildOptions: {
|
|
38
|
+
watch: true
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
});
|
|
37
42
|
await hookRunners.beforeDev();
|
|
@@ -6,16 +6,40 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { bundle } from '@modern-js/node-bundle-require';
|
|
9
|
-
import {
|
|
9
|
+
import { CONFIG_FILE_EXTENSIONS, fs, getServerConfig, OUTPUT_CONFIG_FILE } from '@modern-js/utils';
|
|
10
10
|
export const defineServerConfig = config => config;
|
|
11
|
-
export const buildServerConfig = async (
|
|
11
|
+
export const buildServerConfig = async ({
|
|
12
|
+
appDirectory,
|
|
13
|
+
distDirectory,
|
|
14
|
+
configFile,
|
|
15
|
+
options
|
|
16
|
+
}) => {
|
|
17
|
+
const helperCode = `
|
|
18
|
+
export const defineConfig = (config) => config;
|
|
19
|
+
`;
|
|
12
20
|
const configFilePath = await getServerConfig(appDirectory, configFile);
|
|
13
21
|
|
|
14
|
-
const getOutputFile = filepath => path.resolve(
|
|
22
|
+
const getOutputFile = filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
15
23
|
|
|
16
24
|
if (configFilePath) {
|
|
25
|
+
const configHelperFilePath = path.join(distDirectory, './config-helper.js');
|
|
26
|
+
await fs.writeFile(configHelperFilePath, helperCode);
|
|
17
27
|
await bundle(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
18
|
-
getOutputFile
|
|
28
|
+
getOutputFile,
|
|
29
|
+
esbuildPlugins: [{
|
|
30
|
+
name: 'native-build-config',
|
|
31
|
+
|
|
32
|
+
setup(ctx) {
|
|
33
|
+
ctx.onResolve({
|
|
34
|
+
filter: /app-tools\/server/
|
|
35
|
+
}, () => {
|
|
36
|
+
return {
|
|
37
|
+
path: configHelperFilePath
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}]
|
|
19
43
|
}));
|
|
20
44
|
}
|
|
21
45
|
};
|
|
@@ -25,7 +25,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
25
25
|
|
|
26
26
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
27
27
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
28
|
-
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
28
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
29
29
|
|
|
30
30
|
const build = async (api, options) => {
|
|
31
31
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -115,7 +115,11 @@ const build = async (api, options) => {
|
|
|
115
115
|
} = appContext;
|
|
116
116
|
const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
|
|
117
117
|
await (0, _utils.emptyDir)(distDirectory);
|
|
118
|
-
await (0, _config.buildServerConfig)(
|
|
118
|
+
await (0, _config.buildServerConfig)({
|
|
119
|
+
appDirectory,
|
|
120
|
+
distDirectory,
|
|
121
|
+
configFile: serverConfigFile
|
|
122
|
+
});
|
|
119
123
|
const buildConfigs = [];
|
|
120
124
|
buildConfigs.push({
|
|
121
125
|
type: 'legacy',
|
|
@@ -49,9 +49,14 @@ const dev = async (api, options) => {
|
|
|
49
49
|
|
|
50
50
|
_utils.fs.emptyDirSync(distDirectory);
|
|
51
51
|
|
|
52
|
-
await (0, _config.buildServerConfig)(
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
await (0, _config.buildServerConfig)({
|
|
53
|
+
appDirectory,
|
|
54
|
+
distDirectory,
|
|
55
|
+
configFile: serverConfigFile,
|
|
56
|
+
options: {
|
|
57
|
+
esbuildOptions: {
|
|
58
|
+
watch: true
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
});
|
|
57
62
|
await hookRunners.beforeDev();
|
|
@@ -25,14 +25,38 @@ const defineServerConfig = config => config;
|
|
|
25
25
|
|
|
26
26
|
exports.defineServerConfig = defineServerConfig;
|
|
27
27
|
|
|
28
|
-
const buildServerConfig = async (
|
|
28
|
+
const buildServerConfig = async ({
|
|
29
|
+
appDirectory,
|
|
30
|
+
distDirectory,
|
|
31
|
+
configFile,
|
|
32
|
+
options
|
|
33
|
+
}) => {
|
|
34
|
+
const helperCode = `
|
|
35
|
+
export const defineConfig = (config) => config;
|
|
36
|
+
`;
|
|
29
37
|
const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
|
|
30
38
|
|
|
31
|
-
const getOutputFile = filepath => path.resolve(
|
|
39
|
+
const getOutputFile = filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
|
|
32
40
|
|
|
33
41
|
if (configFilePath) {
|
|
42
|
+
const configHelperFilePath = path.join(distDirectory, './config-helper.js');
|
|
43
|
+
await _utils.fs.writeFile(configHelperFilePath, helperCode);
|
|
34
44
|
await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
|
|
35
|
-
getOutputFile
|
|
45
|
+
getOutputFile,
|
|
46
|
+
esbuildPlugins: [{
|
|
47
|
+
name: 'native-build-config',
|
|
48
|
+
|
|
49
|
+
setup(ctx) {
|
|
50
|
+
ctx.onResolve({
|
|
51
|
+
filter: /app-tools\/server/
|
|
52
|
+
}, () => {
|
|
53
|
+
return {
|
|
54
|
+
path: configHelperFilePath
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}]
|
|
36
60
|
}));
|
|
37
61
|
}
|
|
38
62
|
};
|
|
@@ -2,7 +2,17 @@ import { bundle } from '@modern-js/node-bundle-require';
|
|
|
2
2
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
3
3
|
import type { ServerConfig } from '@modern-js/server-core';
|
|
4
4
|
export declare const defineServerConfig: (config: ServerConfig) => ServerConfig;
|
|
5
|
-
export declare const buildServerConfig: (
|
|
5
|
+
export declare const buildServerConfig: ({
|
|
6
|
+
appDirectory,
|
|
7
|
+
distDirectory,
|
|
8
|
+
configFile,
|
|
9
|
+
options
|
|
10
|
+
}: {
|
|
11
|
+
appDirectory: string;
|
|
12
|
+
distDirectory: string;
|
|
13
|
+
configFile: string;
|
|
14
|
+
options?: Parameters<typeof bundle>[1];
|
|
15
|
+
}) => Promise<void>;
|
|
6
16
|
/**
|
|
7
17
|
*
|
|
8
18
|
* 处理循环引用的 replacer
|