@modern-js/app-tools 1.3.0 → 1.4.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 +87 -0
- package/dist/js/modern/commands/build.js +24 -8
- package/dist/js/modern/commands/dev.js +32 -12
- package/dist/js/modern/index.js +30 -6
- package/dist/js/modern/locale/en.js +2 -1
- package/dist/js/modern/locale/zh.js +2 -1
- package/dist/js/modern/utils/createServer.js +8 -1
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/printInstructions.js +4 -1
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/commands/build.js +24 -7
- package/dist/js/node/commands/dev.js +36 -11
- package/dist/js/node/index.js +32 -5
- package/dist/js/node/locale/en.js +2 -1
- package/dist/js/node/locale/zh.js +2 -1
- package/dist/js/node/utils/createServer.js +15 -2
- package/dist/js/node/utils/getSpecifiedEntries.js +48 -0
- package/dist/js/node/utils/printInstructions.js +4 -1
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/dist/types/utils/createServer.d.ts +2 -0
- package/dist/types/utils/getSpecifiedEntries.d.ts +2 -0
- package/dist/types/utils/routes.d.ts +3 -0
- package/dist/types/utils/types.d.ts +3 -0
- package/lib/types.d.ts +0 -10
- package/package.json +16 -16
- package/tests/commands/build.test.ts +37 -0
- package/tests/commands/dev.test.ts +7 -0
- package/tests/routes.test.ts +27 -0
- package/tests/tsconfig.json +13 -0
- package/tests/utils.test.ts +67 -0
- 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 -81
- 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,92 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 78279953: compiler entry bug fix and dev build console
|
|
8
|
+
- c78400c7: fix: remove stylus support
|
|
9
|
+
- 4d72edea: support dev compiler by entry
|
|
10
|
+
- Updated dependencies [75f4eeb8]
|
|
11
|
+
- Updated dependencies [b7a9eeba]
|
|
12
|
+
- Updated dependencies [2cfc4235]
|
|
13
|
+
- Updated dependencies [8d55e234]
|
|
14
|
+
- Updated dependencies [53aca274]
|
|
15
|
+
- Updated dependencies [78279953]
|
|
16
|
+
- Updated dependencies [e116ace5]
|
|
17
|
+
- Updated dependencies [4d72edea]
|
|
18
|
+
- @modern-js/webpack@1.3.1
|
|
19
|
+
- @modern-js/plugin-analyze@1.3.1
|
|
20
|
+
- @modern-js/server@1.4.1
|
|
21
|
+
- @modern-js/core@1.4.1
|
|
22
|
+
- @modern-js/types@1.3.1
|
|
23
|
+
- @modern-js/utils@1.3.1
|
|
24
|
+
|
|
25
|
+
## 1.4.0
|
|
26
|
+
|
|
27
|
+
### Minor Changes
|
|
28
|
+
|
|
29
|
+
- ec4dbffb: feat: support as a pure api service
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- bd819a8d: fix: file route changed not trigger hot reload
|
|
34
|
+
- 62cd58c6: fix: create route.json failure
|
|
35
|
+
- d099e5c5: fix error when modify modern.config.js
|
|
36
|
+
- Updated dependencies [816fd721]
|
|
37
|
+
- Updated dependencies [d9cc5ea9]
|
|
38
|
+
- Updated dependencies [ddf0c3a6]
|
|
39
|
+
- Updated dependencies [bfbea9a7]
|
|
40
|
+
- Updated dependencies [bd819a8d]
|
|
41
|
+
- Updated dependencies [ec4dbffb]
|
|
42
|
+
- Updated dependencies [d099e5c5]
|
|
43
|
+
- Updated dependencies [bada2879]
|
|
44
|
+
- Updated dependencies [24f616ca]
|
|
45
|
+
- Updated dependencies [bd819a8d]
|
|
46
|
+
- Updated dependencies [272cab15]
|
|
47
|
+
- @modern-js/server@1.4.0
|
|
48
|
+
- @modern-js/types@1.3.0
|
|
49
|
+
- @modern-js/core@1.4.0
|
|
50
|
+
- @modern-js/plugin-analyze@1.3.0
|
|
51
|
+
- @modern-js/webpack@1.3.0
|
|
52
|
+
- @modern-js/utils@1.3.0
|
|
53
|
+
|
|
54
|
+
## 1.3.2
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- 83166714: change .npmignore
|
|
59
|
+
- Updated dependencies [83166714]
|
|
60
|
+
- Updated dependencies [c3de9882]
|
|
61
|
+
- Updated dependencies [33ff48af]
|
|
62
|
+
- Updated dependencies [b7c48198]
|
|
63
|
+
- @modern-js/core@1.3.2
|
|
64
|
+
- @modern-js/i18n-cli-language-detector@1.2.1
|
|
65
|
+
- @modern-js/plugin-analyze@1.2.1
|
|
66
|
+
- @modern-js/plugin-fast-refresh@1.2.1
|
|
67
|
+
- @modern-js/plugin-i18n@1.2.1
|
|
68
|
+
- @modern-js/webpack@1.2.1
|
|
69
|
+
- @modern-js/new-action@1.3.1
|
|
70
|
+
- @modern-js/server@1.3.2
|
|
71
|
+
- @modern-js/plugin@1.2.1
|
|
72
|
+
- @modern-js/types@1.2.1
|
|
73
|
+
- @modern-js/utils@1.2.2
|
|
74
|
+
|
|
75
|
+
## 1.3.1
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- 823809c6: fix: remove plugin-polyfill from app-tools
|
|
80
|
+
- Updated dependencies [e2d3a575]
|
|
81
|
+
- Updated dependencies [823809c6]
|
|
82
|
+
- Updated dependencies [823809c6]
|
|
83
|
+
- Updated dependencies [4584cc04]
|
|
84
|
+
- Updated dependencies [7c19fd94]
|
|
85
|
+
- Updated dependencies [e2d3a575]
|
|
86
|
+
- @modern-js/server@1.3.1
|
|
87
|
+
- @modern-js/utils@1.2.1
|
|
88
|
+
- @modern-js/core@1.3.1
|
|
89
|
+
|
|
3
90
|
## 1.3.0
|
|
4
91
|
|
|
5
92
|
### 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
|
};
|
|
@@ -6,10 +6,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
|
8
8
|
import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-js/utils';
|
|
9
|
-
import { useAppContext, useResolvedConfigContext, mountHook } from '@modern-js/core';
|
|
9
|
+
import { useAppContext, useResolvedConfigContext, mountHook, AppContext } from '@modern-js/core';
|
|
10
10
|
import { createCompiler } from "../utils/createCompiler";
|
|
11
11
|
import { createServer } from "../utils/createServer";
|
|
12
|
-
|
|
12
|
+
import { generateRoutes } from "../utils/routes";
|
|
13
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
14
|
+
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
15
|
+
export const dev = async options => {
|
|
13
16
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
14
17
|
const appContext = useAppContext();
|
|
15
18
|
const userConfig = useResolvedConfigContext();
|
|
@@ -18,16 +21,29 @@ export const dev = async () => {
|
|
|
18
21
|
const {
|
|
19
22
|
appDirectory,
|
|
20
23
|
distDirectory,
|
|
21
|
-
port
|
|
24
|
+
port,
|
|
25
|
+
existSrc,
|
|
26
|
+
entrypoints
|
|
22
27
|
} = appContext;
|
|
28
|
+
const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
|
|
29
|
+
AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
30
|
+
checkedEntries
|
|
31
|
+
}));
|
|
32
|
+
appContext.checkedEntries = checkedEntries;
|
|
23
33
|
fs.emptyDirSync(distDirectory);
|
|
24
34
|
await mountHook().beforeDev();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
userConfig,
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
let compiler = null;
|
|
36
|
+
|
|
37
|
+
if (existSrc) {
|
|
38
|
+
const webpackConfigs = [isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
39
|
+
compiler = await createCompiler({
|
|
40
|
+
webpackConfigs,
|
|
41
|
+
userConfig,
|
|
42
|
+
appContext
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await generateRoutes(appContext);
|
|
31
47
|
const app = await createServer({
|
|
32
48
|
dev: _objectSpread(_objectSpread({}, {
|
|
33
49
|
client: {
|
|
@@ -50,12 +66,16 @@ export const dev = async () => {
|
|
|
50
66
|
config: userConfig,
|
|
51
67
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
52
68
|
});
|
|
53
|
-
app.listen(port, err => {
|
|
69
|
+
app.listen(port, async err => {
|
|
54
70
|
if (err) {
|
|
55
71
|
throw err;
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
if (existSrc) {
|
|
75
|
+
clearConsole();
|
|
76
|
+
logger.log(chalk.cyan(`Starting the development server...`));
|
|
77
|
+
} else {
|
|
78
|
+
await printInstructions(appContext, userConfig);
|
|
79
|
+
}
|
|
60
80
|
});
|
|
61
81
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -4,15 +4,18 @@ 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";
|
|
11
13
|
import { start } from "./commands/start";
|
|
12
14
|
import { dev } from "./commands/dev";
|
|
15
|
+
import { closeServer } from "./utils/createServer";
|
|
13
16
|
export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
17
|
|
|
15
|
-
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')
|
|
18
|
+
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
16
19
|
export default createPlugin(() => {
|
|
17
20
|
const locale = getLocaleLanguage();
|
|
18
21
|
i18n.changeLanguage({
|
|
@@ -23,8 +26,8 @@ export default createPlugin(() => {
|
|
|
23
26
|
commands({
|
|
24
27
|
program
|
|
25
28
|
}) {
|
|
26
|
-
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).
|
|
27
|
-
await dev();
|
|
29
|
+
program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).action(async options => {
|
|
30
|
+
await dev(options);
|
|
28
31
|
});
|
|
29
32
|
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
|
|
30
33
|
const {
|
|
@@ -60,11 +63,32 @@ export default createPlugin(() => {
|
|
|
60
63
|
});
|
|
61
64
|
},
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
67
|
+
async fileChange(e) {
|
|
68
|
+
const {
|
|
69
|
+
filename,
|
|
70
|
+
eventType
|
|
71
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
72
|
+
|
|
73
|
+
const appContext = useAppContext();
|
|
74
|
+
const {
|
|
75
|
+
appDirectory,
|
|
76
|
+
srcDirectory
|
|
77
|
+
} = appContext;
|
|
78
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
79
|
+
|
|
80
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
81
|
+
await closeServer();
|
|
82
|
+
await cli.restart();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async beforeRestart() {
|
|
87
|
+
cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
65
88
|
}
|
|
66
89
|
|
|
67
90
|
};
|
|
68
91
|
}, {
|
|
92
|
+
name: '@modern-js/app-tools',
|
|
69
93
|
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
94
|
});
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Server } from '@modern-js/server';
|
|
2
|
-
let server;
|
|
2
|
+
let server = null;
|
|
3
|
+
export const getServer = () => server;
|
|
4
|
+
export const closeServer = async () => {
|
|
5
|
+
if (server) {
|
|
6
|
+
await server.close();
|
|
7
|
+
server = null;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
3
10
|
export const createServer = async options => {
|
|
4
11
|
if (server) {
|
|
5
12
|
await server.close();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
export const getSpecifiedEntries = async (entry, entrypoints) => {
|
|
3
|
+
const entryNames = entrypoints.map(e => e.entryName);
|
|
4
|
+
|
|
5
|
+
if (!entry) {
|
|
6
|
+
return entryNames;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof entry === 'boolean') {
|
|
10
|
+
const {
|
|
11
|
+
selected
|
|
12
|
+
} = await inquirer.prompt([{
|
|
13
|
+
type: 'checkbox',
|
|
14
|
+
name: 'selected',
|
|
15
|
+
choices: entryNames,
|
|
16
|
+
message: '请选择需要构建的入口',
|
|
17
|
+
|
|
18
|
+
validate(answer) {
|
|
19
|
+
if (answer.length < 1) {
|
|
20
|
+
return 'You must choose at least one topping.';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}]);
|
|
27
|
+
return selected;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
entry.forEach(name => {
|
|
31
|
+
if (!entryNames.includes(name)) {
|
|
32
|
+
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return entry;
|
|
36
|
+
};
|
|
@@ -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 };
|
|
File without changes
|
|
@@ -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,13 +15,19 @@ 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
|
+
|
|
22
|
+
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
|
23
|
+
|
|
18
24
|
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
25
|
|
|
20
26
|
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; }
|
|
21
27
|
|
|
22
28
|
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; }
|
|
23
29
|
|
|
24
|
-
const dev = async
|
|
30
|
+
const dev = async options => {
|
|
25
31
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
26
32
|
const appContext = (0, _core.useAppContext)();
|
|
27
33
|
const userConfig = (0, _core.useResolvedConfigContext)();
|
|
@@ -30,18 +36,33 @@ const dev = async () => {
|
|
|
30
36
|
const {
|
|
31
37
|
appDirectory,
|
|
32
38
|
distDirectory,
|
|
33
|
-
port
|
|
39
|
+
port,
|
|
40
|
+
existSrc,
|
|
41
|
+
entrypoints
|
|
34
42
|
} = appContext;
|
|
43
|
+
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
|
44
|
+
|
|
45
|
+
_core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
46
|
+
checkedEntries
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
appContext.checkedEntries = checkedEntries;
|
|
35
50
|
|
|
36
51
|
_utils.fs.emptyDirSync(distDirectory);
|
|
37
52
|
|
|
38
53
|
await (0, _core.mountHook)().beforeDev();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
userConfig,
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
let compiler = null;
|
|
55
|
+
|
|
56
|
+
if (existSrc) {
|
|
57
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE), (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT)].filter(Boolean);
|
|
58
|
+
compiler = await (0, _createCompiler.createCompiler)({
|
|
59
|
+
webpackConfigs,
|
|
60
|
+
userConfig,
|
|
61
|
+
appContext
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
45
66
|
const app = await (0, _createServer.createServer)({
|
|
46
67
|
dev: _objectSpread(_objectSpread({}, {
|
|
47
68
|
client: {
|
|
@@ -64,14 +85,18 @@ const dev = async () => {
|
|
|
64
85
|
config: userConfig,
|
|
65
86
|
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
|
66
87
|
});
|
|
67
|
-
app.listen(port, err => {
|
|
88
|
+
app.listen(port, async err => {
|
|
68
89
|
if (err) {
|
|
69
90
|
throw err;
|
|
70
91
|
}
|
|
71
92
|
|
|
72
|
-
|
|
93
|
+
if (existSrc) {
|
|
94
|
+
(0, _utils.clearConsole)();
|
|
73
95
|
|
|
74
|
-
|
|
96
|
+
_utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
|
97
|
+
} else {
|
|
98
|
+
await (0, _printInstructions.printInstructions)(appContext, userConfig);
|
|
99
|
+
}
|
|
75
100
|
});
|
|
76
101
|
};
|
|
77
102
|
|
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");
|
|
@@ -23,6 +27,8 @@ var _start = require("./commands/start");
|
|
|
23
27
|
|
|
24
28
|
var _dev = require("./commands/dev");
|
|
25
29
|
|
|
30
|
+
var _createServer = require("./utils/createServer");
|
|
31
|
+
|
|
26
32
|
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; }
|
|
27
33
|
|
|
28
34
|
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; }
|
|
@@ -34,7 +40,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
34
40
|
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
41
|
|
|
36
42
|
// 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')
|
|
43
|
+
(0, _core.usePlugins)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
38
44
|
|
|
39
45
|
var _default = (0, _core.createPlugin)(() => {
|
|
40
46
|
const locale = (0, _language.getLocaleLanguage)();
|
|
@@ -48,8 +54,8 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
48
54
|
commands({
|
|
49
55
|
program
|
|
50
56
|
}) {
|
|
51
|
-
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.dev.config)).
|
|
52
|
-
await (0, _dev.dev)();
|
|
57
|
+
program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.dev.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).action(async options => {
|
|
58
|
+
await (0, _dev.dev)(options);
|
|
53
59
|
});
|
|
54
60
|
program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.build.analyze)).action(async options => {
|
|
55
61
|
const {
|
|
@@ -85,12 +91,33 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
85
91
|
});
|
|
86
92
|
},
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
95
|
+
async fileChange(e) {
|
|
96
|
+
const {
|
|
97
|
+
filename,
|
|
98
|
+
eventType
|
|
99
|
+
} = e; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
|
+
|
|
101
|
+
const appContext = (0, _core.useAppContext)();
|
|
102
|
+
const {
|
|
103
|
+
appDirectory,
|
|
104
|
+
srcDirectory
|
|
105
|
+
} = appContext;
|
|
106
|
+
const absolutePath = path.resolve(appDirectory, filename);
|
|
107
|
+
|
|
108
|
+
if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
|
|
109
|
+
await (0, _createServer.closeServer)();
|
|
110
|
+
await _core.cli.restart();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
async beforeRestart() {
|
|
115
|
+
(0, _utils.cleanRequireCache)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
};
|
|
93
119
|
}, {
|
|
120
|
+
name: '@modern-js/app-tools',
|
|
94
121
|
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
122
|
});
|
|
96
123
|
|
|
@@ -3,11 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createServer = void 0;
|
|
6
|
+
exports.getServer = exports.createServer = exports.closeServer = void 0;
|
|
7
7
|
|
|
8
8
|
var _server = require("@modern-js/server");
|
|
9
9
|
|
|
10
|
-
let server;
|
|
10
|
+
let server = null;
|
|
11
|
+
|
|
12
|
+
const getServer = () => server;
|
|
13
|
+
|
|
14
|
+
exports.getServer = getServer;
|
|
15
|
+
|
|
16
|
+
const closeServer = async () => {
|
|
17
|
+
if (server) {
|
|
18
|
+
await server.close();
|
|
19
|
+
server = null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.closeServer = closeServer;
|
|
11
24
|
|
|
12
25
|
const createServer = async options => {
|
|
13
26
|
if (server) {
|