@modern-js/app-tools 1.2.0 → 1.4.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 +100 -0
- package/dist/js/modern/commands/build.js +24 -8
- package/dist/js/modern/commands/dev.js +23 -10
- package/dist/js/modern/index.js +26 -4
- package/dist/js/modern/utils/createCompiler.js +2 -1
- package/dist/js/modern/utils/printInstructions.js +4 -1
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/node/commands/build.js +24 -7
- package/dist/js/node/commands/dev.js +25 -10
- package/dist/js/node/index.js +27 -3
- package/dist/js/node/utils/createCompiler.js +2 -1
- package/dist/js/node/utils/printInstructions.js +4 -1
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -0
- package/jest.config.js +8 -0
- package/package.json +27 -19
- package/tests/commands/build.test.ts +37 -0
- package/tests/commands/dev.test.ts +7 -0
- package/tests/index.test.ts +7 -0
- package/tests/routes.test.ts +27 -0
- package/tests/tsconfig.json +13 -0
- package/tsconfig.json +1 -3
- package/src/commands/build.ts +0 -129
- package/src/commands/deploy.ts +0 -6
- package/src/commands/dev.ts +0 -80
- package/src/commands/index.ts +0 -3
- package/src/commands/start.ts +0 -30
- package/src/index.ts +0 -100
- package/src/lifecycle.ts +0 -43
- package/src/locale/en.ts +0 -18
- package/src/locale/index.ts +0 -9
- package/src/locale/zh.ts +0 -18
- package/src/utils/createCompiler.ts +0 -80
- package/src/utils/createServer.ts +0 -16
- package/src/utils/language.ts +0 -6
- package/src/utils/printInstructions.ts +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,105 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ec4dbffb: feat: support as a pure api service
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- bd819a8d: fix: file route changed not trigger hot reload
|
|
12
|
+
- 62cd58c6: fix: create route.json failure
|
|
13
|
+
- d099e5c5: fix error when modify modern.config.js
|
|
14
|
+
- Updated dependencies [816fd721]
|
|
15
|
+
- Updated dependencies [d9cc5ea9]
|
|
16
|
+
- Updated dependencies [ddf0c3a6]
|
|
17
|
+
- Updated dependencies [bfbea9a7]
|
|
18
|
+
- Updated dependencies [bd819a8d]
|
|
19
|
+
- Updated dependencies [ec4dbffb]
|
|
20
|
+
- Updated dependencies [d099e5c5]
|
|
21
|
+
- Updated dependencies [bada2879]
|
|
22
|
+
- Updated dependencies [24f616ca]
|
|
23
|
+
- Updated dependencies [bd819a8d]
|
|
24
|
+
- Updated dependencies [272cab15]
|
|
25
|
+
- @modern-js/server@1.4.0
|
|
26
|
+
- @modern-js/types@1.3.0
|
|
27
|
+
- @modern-js/core@1.4.0
|
|
28
|
+
- @modern-js/plugin-analyze@1.3.0
|
|
29
|
+
- @modern-js/webpack@1.3.0
|
|
30
|
+
- @modern-js/utils@1.3.0
|
|
31
|
+
|
|
32
|
+
## 1.3.2
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 83166714: change .npmignore
|
|
37
|
+
- Updated dependencies [83166714]
|
|
38
|
+
- Updated dependencies [c3de9882]
|
|
39
|
+
- Updated dependencies [33ff48af]
|
|
40
|
+
- Updated dependencies [b7c48198]
|
|
41
|
+
- @modern-js/core@1.3.2
|
|
42
|
+
- @modern-js/i18n-cli-language-detector@1.2.1
|
|
43
|
+
- @modern-js/plugin-analyze@1.2.1
|
|
44
|
+
- @modern-js/plugin-fast-refresh@1.2.1
|
|
45
|
+
- @modern-js/plugin-i18n@1.2.1
|
|
46
|
+
- @modern-js/webpack@1.2.1
|
|
47
|
+
- @modern-js/new-action@1.3.1
|
|
48
|
+
- @modern-js/server@1.3.2
|
|
49
|
+
- @modern-js/plugin@1.2.1
|
|
50
|
+
- @modern-js/types@1.2.1
|
|
51
|
+
- @modern-js/utils@1.2.2
|
|
52
|
+
|
|
53
|
+
## 1.3.1
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- 823809c6: fix: remove plugin-polyfill from app-tools
|
|
58
|
+
- Updated dependencies [e2d3a575]
|
|
59
|
+
- Updated dependencies [823809c6]
|
|
60
|
+
- Updated dependencies [823809c6]
|
|
61
|
+
- Updated dependencies [4584cc04]
|
|
62
|
+
- Updated dependencies [7c19fd94]
|
|
63
|
+
- Updated dependencies [e2d3a575]
|
|
64
|
+
- @modern-js/server@1.3.1
|
|
65
|
+
- @modern-js/utils@1.2.1
|
|
66
|
+
- @modern-js/core@1.3.1
|
|
67
|
+
|
|
68
|
+
## 1.3.0
|
|
69
|
+
|
|
70
|
+
### Minor Changes
|
|
71
|
+
|
|
72
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
73
|
+
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- Updated dependencies [2da09c69]
|
|
77
|
+
- Updated dependencies [e2464fe5]
|
|
78
|
+
- Updated dependencies [5597289b]
|
|
79
|
+
- Updated dependencies [fc71e36f]
|
|
80
|
+
- Updated dependencies [4a85378c]
|
|
81
|
+
- Updated dependencies [146dcd85]
|
|
82
|
+
- Updated dependencies [e453e421]
|
|
83
|
+
- Updated dependencies [2c049918]
|
|
84
|
+
- Updated dependencies [c3d46ee4]
|
|
85
|
+
- Updated dependencies [cfe11628]
|
|
86
|
+
- Updated dependencies [1ebc7ee2]
|
|
87
|
+
- Updated dependencies [146dcd85]
|
|
88
|
+
- Updated dependencies [146dcd85]
|
|
89
|
+
- Updated dependencies [1ebc7ee2]
|
|
90
|
+
- @modern-js/utils@1.2.0
|
|
91
|
+
- @modern-js/types@1.2.0
|
|
92
|
+
- @modern-js/webpack@1.2.0
|
|
93
|
+
- @modern-js/core@1.3.0
|
|
94
|
+
- @modern-js/server@1.3.0
|
|
95
|
+
- @modern-js/new-action@1.3.0
|
|
96
|
+
- @modern-js/i18n-cli-language-detector@1.2.0
|
|
97
|
+
- @modern-js/plugin-analyze@1.2.0
|
|
98
|
+
- @modern-js/plugin-fast-refresh@1.2.0
|
|
99
|
+
- @modern-js/plugin-i18n@1.2.0
|
|
100
|
+
- @modern-js/plugin-polyfill@1.2.0
|
|
101
|
+
- @modern-js/plugin@1.2.0
|
|
102
|
+
|
|
3
103
|
## 1.2.0
|
|
4
104
|
|
|
5
105
|
### Minor Changes
|
|
@@ -7,11 +7,30 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
7
7
|
import { webpack } from 'webpack';
|
|
8
8
|
import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
|
|
9
9
|
import { useAppContext, useResolvedConfigContext, mountHook, ResolvedConfigContext, manager } from '@modern-js/core';
|
|
10
|
-
import { fs, formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle } from '@modern-js/utils';
|
|
10
|
+
import { fs, formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle } from '@modern-js/utils';
|
|
11
|
+
import { generateRoutes } from "../utils/routes"; // These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
11
12
|
|
|
12
13
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
13
14
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
15
|
+
// eslint-disable-next-line max-statements
|
|
14
16
|
export const build = async options => {
|
|
17
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
18
|
+
const resolvedConfig = useResolvedConfigContext();
|
|
19
|
+
const appContext = useAppContext();
|
|
20
|
+
const {
|
|
21
|
+
existSrc
|
|
22
|
+
} = appContext;
|
|
23
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
24
|
+
|
|
25
|
+
if (!existSrc) {
|
|
26
|
+
await mountHook().beforeBuild({
|
|
27
|
+
webpackConfigs: []
|
|
28
|
+
});
|
|
29
|
+
await generateRoutes(appContext);
|
|
30
|
+
await mountHook().afterBuild();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
15
34
|
const webpackBuild = async (webpackConfig, type) => {
|
|
16
35
|
const compiler = webpack(webpackConfig);
|
|
17
36
|
return new Promise((resolve, reject) => {
|
|
@@ -62,12 +81,6 @@ export const build = async options => {
|
|
|
62
81
|
});
|
|
63
82
|
});
|
|
64
83
|
};
|
|
65
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const resolvedConfig = useResolvedConfigContext();
|
|
69
|
-
const appContext = useAppContext();
|
|
70
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
71
84
|
|
|
72
85
|
manager.run(() => {
|
|
73
86
|
ResolvedConfigContext.set(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
@@ -112,9 +125,12 @@ export const build = async options => {
|
|
|
112
125
|
try {
|
|
113
126
|
await webpackBuild(config, buildType);
|
|
114
127
|
} catch (error) {
|
|
115
|
-
printBuildError(error);
|
|
128
|
+
printBuildError(error); // eslint-disable-next-line no-process-exit
|
|
129
|
+
|
|
130
|
+
process.exit(1);
|
|
116
131
|
}
|
|
117
132
|
}
|
|
118
133
|
|
|
134
|
+
await generateRoutes(appContext);
|
|
119
135
|
await mountHook().afterBuild();
|
|
120
136
|
};
|
|
@@ -9,6 +9,8 @@ import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-j
|
|
|
9
9
|
import { useAppContext, useResolvedConfigContext, mountHook } from '@modern-js/core';
|
|
10
10
|
import { createCompiler } from "../utils/createCompiler";
|
|
11
11
|
import { createServer } from "../utils/createServer";
|
|
12
|
+
import { generateRoutes } from "../utils/routes";
|
|
13
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
12
14
|
export const dev = async () => {
|
|
13
15
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
14
16
|
const appContext = useAppContext();
|
|
@@ -18,16 +20,23 @@ export const dev = async () => {
|
|
|
18
20
|
const {
|
|
19
21
|
appDirectory,
|
|
20
22
|
distDirectory,
|
|
21
|
-
port
|
|
23
|
+
port,
|
|
24
|
+
existSrc
|
|
22
25
|
} = appContext;
|
|
23
26
|
fs.emptyDirSync(distDirectory);
|
|
24
27
|
await mountHook().beforeDev();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
userConfig,
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
let compiler = null;
|
|
29
|
+
|
|
30
|
+
if (existSrc) {
|
|
31
|
+
const webpackConfigs = [isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
32
|
+
compiler = await createCompiler({
|
|
33
|
+
webpackConfigs,
|
|
34
|
+
userConfig,
|
|
35
|
+
appContext
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await generateRoutes(appContext);
|
|
31
40
|
const app = await createServer({
|
|
32
41
|
dev: _objectSpread(_objectSpread({}, {
|
|
33
42
|
client: {
|
|
@@ -50,12 +59,16 @@ export const dev = async () => {
|
|
|
50
59
|
config: userConfig,
|
|
51
60
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
52
61
|
});
|
|
53
|
-
app.listen(port, err => {
|
|
62
|
+
app.listen(port, async err => {
|
|
54
63
|
if (err) {
|
|
55
64
|
throw err;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
if (existSrc) {
|
|
68
|
+
clearConsole();
|
|
69
|
+
logger.log(chalk.cyan(`Starting the development server...`));
|
|
70
|
+
} else {
|
|
71
|
+
await printInstructions(appContext, userConfig);
|
|
72
|
+
}
|
|
60
73
|
});
|
|
61
74
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -4,7 +4,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { createPlugin, defineConfig, usePlugins, cli, useAppContext } from '@modern-js/core';
|
|
9
|
+
import { cleanRequireCache } from '@modern-js/utils';
|
|
8
10
|
import { lifecycle } from "./lifecycle";
|
|
9
11
|
import { i18n, localeKeys } from "./locale";
|
|
10
12
|
import { getLocaleLanguage } from "./utils/language";
|
|
@@ -12,7 +14,7 @@ import { start } from "./commands/start";
|
|
|
12
14
|
import { dev } from "./commands/dev";
|
|
13
15
|
export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
16
|
|
|
15
|
-
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')
|
|
17
|
+
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
16
18
|
export default createPlugin(() => {
|
|
17
19
|
const locale = getLocaleLanguage();
|
|
18
20
|
i18n.changeLanguage({
|
|
@@ -60,11 +62,31 @@ export default createPlugin(() => {
|
|
|
60
62
|
});
|
|
61
63
|
},
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
66
|
+
async fileChange(e) {
|
|
67
|
+
const {
|
|
68
|
+
filename,
|
|
69
|
+
eventType
|
|
70
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
71
|
+
|
|
72
|
+
const appContext = useAppContext();
|
|
73
|
+
const {
|
|
74
|
+
appDirectory,
|
|
75
|
+
srcDirectory
|
|
76
|
+
} = appContext;
|
|
77
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
78
|
+
|
|
79
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
80
|
+
await cli.restart();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async beforeRestart() {
|
|
85
|
+
cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
};
|
|
68
89
|
}, {
|
|
90
|
+
name: '@modern-js/app-tools',
|
|
69
91
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
|
|
70
92
|
});
|
|
@@ -66,7 +66,8 @@ export const createCompiler = async ({
|
|
|
66
66
|
} catch (err) {
|
|
67
67
|
logger.log(chalk.red(`Failed to compile.`));
|
|
68
68
|
logger.log();
|
|
69
|
-
logger.log(err); //
|
|
69
|
+
logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
|
70
|
+
// eslint-disable-next-line no-process-exit
|
|
70
71
|
|
|
71
72
|
process.exit(1);
|
|
72
73
|
}
|
|
@@ -2,8 +2,11 @@ import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
|
2
2
|
import { mountHook } from '@modern-js/core';
|
|
3
3
|
export const printInstructions = async (appContext, config) => {
|
|
4
4
|
let message = prettyInstructions(appContext, config);
|
|
5
|
+
const {
|
|
6
|
+
existSrc
|
|
7
|
+
} = appContext;
|
|
5
8
|
|
|
6
|
-
if (isDev()) {
|
|
9
|
+
if (isDev() && existSrc) {
|
|
7
10
|
message += `\n${chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
8
11
|
} // call beforePrintInstructions hook.
|
|
9
12
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fs, ROUTE_SPEC_FILE } from '@modern-js/utils';
|
|
3
|
+
|
|
4
|
+
const generateRoutes = async appContext => {
|
|
5
|
+
const {
|
|
6
|
+
serverRoutes,
|
|
7
|
+
distDirectory
|
|
8
|
+
} = appContext;
|
|
9
|
+
const output = JSON.stringify({
|
|
10
|
+
routes: serverRoutes
|
|
11
|
+
}, null, 2);
|
|
12
|
+
await fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { generateRoutes };
|
|
@@ -13,6 +13,8 @@ var _core = require("@modern-js/core");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
+
var _routes = require("../utils/routes");
|
|
17
|
+
|
|
16
18
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
19
|
|
|
18
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -23,7 +25,25 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
23
25
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
24
26
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
25
27
|
|
|
28
|
+
// eslint-disable-next-line max-statements
|
|
26
29
|
const build = async options => {
|
|
30
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
31
|
+
const resolvedConfig = (0, _core.useResolvedConfigContext)();
|
|
32
|
+
const appContext = (0, _core.useAppContext)();
|
|
33
|
+
const {
|
|
34
|
+
existSrc
|
|
35
|
+
} = appContext;
|
|
36
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
|
+
|
|
38
|
+
if (!existSrc) {
|
|
39
|
+
await (0, _core.mountHook)().beforeBuild({
|
|
40
|
+
webpackConfigs: []
|
|
41
|
+
});
|
|
42
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
43
|
+
await (0, _core.mountHook)().afterBuild();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
const webpackBuild = async (webpackConfig, type) => {
|
|
28
48
|
const compiler = (0, _webpack.webpack)(webpackConfig);
|
|
29
49
|
return new Promise((resolve, reject) => {
|
|
@@ -77,12 +97,6 @@ const build = async options => {
|
|
|
77
97
|
});
|
|
78
98
|
});
|
|
79
99
|
};
|
|
80
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const resolvedConfig = (0, _core.useResolvedConfigContext)();
|
|
84
|
-
const appContext = (0, _core.useAppContext)();
|
|
85
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
86
100
|
|
|
87
101
|
_core.manager.run(() => {
|
|
88
102
|
_core.ResolvedConfigContext.set(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
@@ -130,10 +144,13 @@ const build = async options => {
|
|
|
130
144
|
try {
|
|
131
145
|
await webpackBuild(config, buildType);
|
|
132
146
|
} catch (error) {
|
|
133
|
-
(0, _utils.printBuildError)(error);
|
|
147
|
+
(0, _utils.printBuildError)(error); // eslint-disable-next-line no-process-exit
|
|
148
|
+
|
|
149
|
+
process.exit(1);
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
152
|
|
|
153
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
137
154
|
await (0, _core.mountHook)().afterBuild();
|
|
138
155
|
};
|
|
139
156
|
|
|
@@ -15,6 +15,10 @@ var _createCompiler = require("../utils/createCompiler");
|
|
|
15
15
|
|
|
16
16
|
var _createServer = require("../utils/createServer");
|
|
17
17
|
|
|
18
|
+
var _routes = require("../utils/routes");
|
|
19
|
+
|
|
20
|
+
var _printInstructions = require("../utils/printInstructions");
|
|
21
|
+
|
|
18
22
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
23
|
|
|
20
24
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -30,18 +34,25 @@ const dev = async () => {
|
|
|
30
34
|
const {
|
|
31
35
|
appDirectory,
|
|
32
36
|
distDirectory,
|
|
33
|
-
port
|
|
37
|
+
port,
|
|
38
|
+
existSrc
|
|
34
39
|
} = appContext;
|
|
35
40
|
|
|
36
41
|
_utils.fs.emptyDirSync(distDirectory);
|
|
37
42
|
|
|
38
43
|
await (0, _core.mountHook)().beforeDev();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
userConfig,
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
let compiler = null;
|
|
45
|
+
|
|
46
|
+
if (existSrc) {
|
|
47
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE), (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
48
|
+
compiler = await (0, _createCompiler.createCompiler)({
|
|
49
|
+
webpackConfigs,
|
|
50
|
+
userConfig,
|
|
51
|
+
appContext
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
45
56
|
const app = await (0, _createServer.createServer)({
|
|
46
57
|
dev: _objectSpread(_objectSpread({}, {
|
|
47
58
|
client: {
|
|
@@ -64,14 +75,18 @@ const dev = async () => {
|
|
|
64
75
|
config: userConfig,
|
|
65
76
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
66
77
|
});
|
|
67
|
-
app.listen(port, err => {
|
|
78
|
+
app.listen(port, async err => {
|
|
68
79
|
if (err) {
|
|
69
80
|
throw err;
|
|
70
81
|
}
|
|
71
82
|
|
|
72
|
-
|
|
83
|
+
if (existSrc) {
|
|
84
|
+
(0, _utils.clearConsole)();
|
|
73
85
|
|
|
74
|
-
|
|
86
|
+
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
87
|
+
} else {
|
|
88
|
+
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
89
|
+
}
|
|
75
90
|
});
|
|
76
91
|
};
|
|
77
92
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -11,8 +11,12 @@ Object.defineProperty(exports, "defineConfig", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
var path = _interopRequireWildcard(require("path"));
|
|
15
|
+
|
|
14
16
|
var _core = require("@modern-js/core");
|
|
15
17
|
|
|
18
|
+
var _utils = require("@modern-js/utils");
|
|
19
|
+
|
|
16
20
|
var _lifecycle = require("./lifecycle");
|
|
17
21
|
|
|
18
22
|
var _locale = require("./locale");
|
|
@@ -34,7 +38,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
34
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
39
|
|
|
36
40
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
37
|
-
(0, _core.usePlugins)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')
|
|
41
|
+
(0, _core.usePlugins)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
38
42
|
|
|
39
43
|
var _default = (0, _core.createPlugin)(() => {
|
|
40
44
|
const locale = (0, _language.getLocaleLanguage)();
|
|
@@ -85,12 +89,32 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
85
89
|
});
|
|
86
90
|
},
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
93
|
+
async fileChange(e) {
|
|
94
|
+
const {
|
|
95
|
+
filename,
|
|
96
|
+
eventType
|
|
97
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
98
|
+
|
|
99
|
+
const appContext = (0, _core.useAppContext)();
|
|
100
|
+
const {
|
|
101
|
+
appDirectory,
|
|
102
|
+
srcDirectory
|
|
103
|
+
} = appContext;
|
|
104
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
105
|
+
|
|
106
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
107
|
+
await _core.cli.restart();
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async beforeRestart() {
|
|
112
|
+
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
90
113
|
}
|
|
91
114
|
|
|
92
115
|
};
|
|
93
116
|
}, {
|
|
117
|
+
name: '@modern-js/app-tools',
|
|
94
118
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
|
|
95
119
|
});
|
|
96
120
|
|
|
@@ -85,7 +85,8 @@ const createCompiler = async ({
|
|
|
85
85
|
|
|
86
86
|
_utils.logger.log();
|
|
87
87
|
|
|
88
|
-
_utils.logger.log(err); //
|
|
88
|
+
_utils.logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
|
89
|
+
// eslint-disable-next-line no-process-exit
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
process.exit(1);
|
|
@@ -11,8 +11,11 @@ var _core = require("@modern-js/core");
|
|
|
11
11
|
|
|
12
12
|
const printInstructions = async (appContext, config) => {
|
|
13
13
|
let message = (0, _utils.prettyInstructions)(appContext, config);
|
|
14
|
+
const {
|
|
15
|
+
existSrc
|
|
16
|
+
} = appContext;
|
|
14
17
|
|
|
15
|
-
if ((0, _utils.isDev)()) {
|
|
18
|
+
if ((0, _utils.isDev)() && existSrc) {
|
|
16
19
|
message += `\n${_utils.chalk.cyanBright([`Note that the development build is not optimized.`, `To create a production build, execute build command.`].join('\n'))}`;
|
|
17
20
|
} // call beforePrintInstructions hook.
|
|
18
21
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateRoutes = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const generateRoutes = async appContext => {
|
|
15
|
+
const {
|
|
16
|
+
serverRoutes,
|
|
17
|
+
distDirectory
|
|
18
|
+
} = appContext;
|
|
19
|
+
const output = JSON.stringify({
|
|
20
|
+
routes: serverRoutes
|
|
21
|
+
}, null, 2);
|
|
22
|
+
await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.generateRoutes = generateRoutes;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
|
|
|
14
14
|
watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
15
15
|
fileChange: import("@modern-js/core").AsyncWorkflow<{
|
|
16
16
|
filename: string;
|
|
17
|
+
eventType: "add" | "unlink" | "change";
|
|
17
18
|
}, void>;
|
|
18
19
|
beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
20
|
+
beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
19
21
|
} & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
|
|
20
22
|
|
|
21
23
|
export default _default;
|
package/jest.config.js
ADDED