@modern-js/app-tools 1.2.0-rc.0 → 1.3.2
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 +77 -13
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/utils/createCompiler.js +2 -1
- package/dist/js/node/index.js +1 -1
- package/dist/js/node/utils/createCompiler.js +2 -1
- package/jest.config.js +8 -0
- package/package.json +27 -19
- package/tests/index.test.ts +7 -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,6 +1,77 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
-
## 1.2
|
|
3
|
+
## 1.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- Updated dependencies [83166714]
|
|
9
|
+
- Updated dependencies [c3de9882]
|
|
10
|
+
- Updated dependencies [33ff48af]
|
|
11
|
+
- Updated dependencies [b7c48198]
|
|
12
|
+
- @modern-js/core@1.3.2
|
|
13
|
+
- @modern-js/i18n-cli-language-detector@1.2.1
|
|
14
|
+
- @modern-js/plugin-analyze@1.2.1
|
|
15
|
+
- @modern-js/plugin-fast-refresh@1.2.1
|
|
16
|
+
- @modern-js/plugin-i18n@1.2.1
|
|
17
|
+
- @modern-js/webpack@1.2.1
|
|
18
|
+
- @modern-js/new-action@1.3.1
|
|
19
|
+
- @modern-js/server@1.3.2
|
|
20
|
+
- @modern-js/plugin@1.2.1
|
|
21
|
+
- @modern-js/types@1.2.1
|
|
22
|
+
- @modern-js/utils@1.2.2
|
|
23
|
+
|
|
24
|
+
## 1.3.1
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 823809c6: fix: remove plugin-polyfill from app-tools
|
|
29
|
+
- Updated dependencies [e2d3a575]
|
|
30
|
+
- Updated dependencies [823809c6]
|
|
31
|
+
- Updated dependencies [823809c6]
|
|
32
|
+
- Updated dependencies [4584cc04]
|
|
33
|
+
- Updated dependencies [7c19fd94]
|
|
34
|
+
- Updated dependencies [e2d3a575]
|
|
35
|
+
- @modern-js/server@1.3.1
|
|
36
|
+
- @modern-js/utils@1.2.1
|
|
37
|
+
- @modern-js/core@1.3.1
|
|
38
|
+
|
|
39
|
+
## 1.3.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [2da09c69]
|
|
48
|
+
- Updated dependencies [e2464fe5]
|
|
49
|
+
- Updated dependencies [5597289b]
|
|
50
|
+
- Updated dependencies [fc71e36f]
|
|
51
|
+
- Updated dependencies [4a85378c]
|
|
52
|
+
- Updated dependencies [146dcd85]
|
|
53
|
+
- Updated dependencies [e453e421]
|
|
54
|
+
- Updated dependencies [2c049918]
|
|
55
|
+
- Updated dependencies [c3d46ee4]
|
|
56
|
+
- Updated dependencies [cfe11628]
|
|
57
|
+
- Updated dependencies [1ebc7ee2]
|
|
58
|
+
- Updated dependencies [146dcd85]
|
|
59
|
+
- Updated dependencies [146dcd85]
|
|
60
|
+
- Updated dependencies [1ebc7ee2]
|
|
61
|
+
- @modern-js/utils@1.2.0
|
|
62
|
+
- @modern-js/types@1.2.0
|
|
63
|
+
- @modern-js/webpack@1.2.0
|
|
64
|
+
- @modern-js/core@1.3.0
|
|
65
|
+
- @modern-js/server@1.3.0
|
|
66
|
+
- @modern-js/new-action@1.3.0
|
|
67
|
+
- @modern-js/i18n-cli-language-detector@1.2.0
|
|
68
|
+
- @modern-js/plugin-analyze@1.2.0
|
|
69
|
+
- @modern-js/plugin-fast-refresh@1.2.0
|
|
70
|
+
- @modern-js/plugin-i18n@1.2.0
|
|
71
|
+
- @modern-js/plugin-polyfill@1.2.0
|
|
72
|
+
- @modern-js/plugin@1.2.0
|
|
73
|
+
|
|
74
|
+
## 1.2.0
|
|
4
75
|
|
|
5
76
|
### Minor Changes
|
|
6
77
|
|
|
@@ -13,18 +84,11 @@
|
|
|
13
84
|
- Updated dependencies [4819a3c7]
|
|
14
85
|
- Updated dependencies [b7fb82ec]
|
|
15
86
|
- Updated dependencies [81d93503]
|
|
16
|
-
- @modern-js/server@1.2.1
|
|
17
|
-
- @modern-js/types@1.1.5
|
|
18
|
-
- @modern-js/plugin-i18n@1.1.2
|
|
19
|
-
- @modern-js/new-action@1.2.2
|
|
20
|
-
- @modern-js/utils@1.1.6
|
|
21
|
-
- @modern-js/plugin-polyfill@1.1.2-rc.0
|
|
22
|
-
- @modern-js/core@1.2.1-rc.0
|
|
23
|
-
- @modern-js/plugin-analyze@1.1.3-rc.0
|
|
24
|
-
- @modern-js/webpack@1.1.4-rc.0
|
|
25
|
-
- @modern-js/i18n-cli-language-detector@1.1.1
|
|
26
|
-
- @modern-js/plugin-fast-refresh@1.1.2-rc.0
|
|
27
|
-
- @modern-js/plugin@1.1.2
|
|
87
|
+
- @modern-js/server@1.2.1
|
|
88
|
+
- @modern-js/types@1.1.5
|
|
89
|
+
- @modern-js/plugin-i18n@1.1.2
|
|
90
|
+
- @modern-js/new-action@1.2.2
|
|
91
|
+
- @modern-js/utils@1.1.6
|
|
28
92
|
|
|
29
93
|
## 1.1.5
|
|
30
94
|
|
package/dist/js/modern/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { start } from "./commands/start";
|
|
|
12
12
|
import { dev } from "./commands/dev";
|
|
13
13
|
export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
14
|
|
|
15
|
-
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')
|
|
15
|
+
usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
16
16
|
export default createPlugin(() => {
|
|
17
17
|
const locale = getLocaleLanguage();
|
|
18
18
|
i18n.changeLanguage({
|
|
@@ -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
|
}
|
package/dist/js/node/index.js
CHANGED
|
@@ -34,7 +34,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
34
34
|
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
35
|
|
|
36
36
|
// 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')
|
|
37
|
+
(0, _core.usePlugins)([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
|
|
38
38
|
|
|
39
39
|
var _default = (0, _core.createPlugin)(() => {
|
|
40
40
|
const locale = (0, _language.getLocaleLanguage)();
|
|
@@ -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);
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2
|
|
14
|
+
"version": "1.3.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -20,13 +20,20 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/index.ts",
|
|
23
24
|
"import": "./dist/js/modern/index.js",
|
|
24
25
|
"require": "./dist/js/node/index.js"
|
|
25
26
|
},
|
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
|
27
28
|
},
|
|
28
|
-
"./cli":
|
|
29
|
-
|
|
29
|
+
"./cli": {
|
|
30
|
+
"jsnext:source": "./src/index.ts",
|
|
31
|
+
"default": "./dist/js/node/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./type": {
|
|
34
|
+
"jsnext:source": "./lib/types.d.ts",
|
|
35
|
+
"default": "./lib/types.d.ts"
|
|
36
|
+
}
|
|
30
37
|
},
|
|
31
38
|
"typesVersions": {
|
|
32
39
|
"*": {
|
|
@@ -43,18 +50,17 @@
|
|
|
43
50
|
},
|
|
44
51
|
"dependencies": {
|
|
45
52
|
"@babel/runtime": "^7",
|
|
46
|
-
"@modern-js/core": "^1.2
|
|
47
|
-
"@modern-js/types": "^1.1
|
|
48
|
-
"@modern-js/i18n-cli-language-detector": "^1.
|
|
49
|
-
"@modern-js/new-action": "^1.
|
|
50
|
-
"@modern-js/plugin": "^1.1
|
|
51
|
-
"@modern-js/plugin-analyze": "^1.1
|
|
52
|
-
"@modern-js/plugin-fast-refresh": "^1.
|
|
53
|
-
"@modern-js/plugin-i18n": "^1.
|
|
54
|
-
"@modern-js/
|
|
55
|
-
"@modern-js/
|
|
56
|
-
"@modern-js/
|
|
57
|
-
"@modern-js/webpack": "^1.1.4-rc.0",
|
|
53
|
+
"@modern-js/core": "^1.3.2",
|
|
54
|
+
"@modern-js/types": "^1.2.1",
|
|
55
|
+
"@modern-js/i18n-cli-language-detector": "^1.2.1",
|
|
56
|
+
"@modern-js/new-action": "^1.3.1",
|
|
57
|
+
"@modern-js/plugin": "^1.2.1",
|
|
58
|
+
"@modern-js/plugin-analyze": "^1.2.1",
|
|
59
|
+
"@modern-js/plugin-fast-refresh": "^1.2.1",
|
|
60
|
+
"@modern-js/plugin-i18n": "^1.2.1",
|
|
61
|
+
"@modern-js/server": "^1.3.2",
|
|
62
|
+
"@modern-js/utils": "^1.2.2",
|
|
63
|
+
"@modern-js/webpack": "^1.2.1",
|
|
58
64
|
"webpack": "^5.54.0"
|
|
59
65
|
},
|
|
60
66
|
"devDependencies": {
|
|
@@ -63,8 +69,9 @@
|
|
|
63
69
|
"@types/react": "^17",
|
|
64
70
|
"@types/react-dom": "^17",
|
|
65
71
|
"typescript": "^4",
|
|
66
|
-
"@
|
|
67
|
-
"
|
|
72
|
+
"@scripts/build": "0.0.0",
|
|
73
|
+
"jest": "^27",
|
|
74
|
+
"@scripts/jest-config": "0.0.0"
|
|
68
75
|
},
|
|
69
76
|
"sideEffects": false,
|
|
70
77
|
"modernConfig": {
|
|
@@ -74,12 +81,13 @@
|
|
|
74
81
|
},
|
|
75
82
|
"publishConfig": {
|
|
76
83
|
"registry": "https://registry.npmjs.org/",
|
|
77
|
-
"access": "public"
|
|
84
|
+
"access": "public",
|
|
85
|
+
"types": "./dist/types/index.d.ts"
|
|
78
86
|
},
|
|
79
87
|
"scripts": {
|
|
80
88
|
"new": "modern new",
|
|
81
89
|
"build": "modern build",
|
|
82
|
-
"test": "
|
|
90
|
+
"test": "jest --passWithNoTests"
|
|
83
91
|
},
|
|
84
92
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
85
93
|
}
|
package/tsconfig.json
CHANGED
package/src/commands/build.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Configuration, webpack } from 'webpack';
|
|
2
|
-
import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
|
|
3
|
-
import {
|
|
4
|
-
useAppContext,
|
|
5
|
-
useResolvedConfigContext,
|
|
6
|
-
mountHook,
|
|
7
|
-
ResolvedConfigContext,
|
|
8
|
-
manager,
|
|
9
|
-
} from '@modern-js/core';
|
|
10
|
-
import {
|
|
11
|
-
fs,
|
|
12
|
-
formatWebpackMessages,
|
|
13
|
-
measureFileSizesBeforeBuild,
|
|
14
|
-
printFileSizesAfterBuild,
|
|
15
|
-
printBuildError,
|
|
16
|
-
logger,
|
|
17
|
-
isUseSSRBundle,
|
|
18
|
-
} from '@modern-js/utils';
|
|
19
|
-
|
|
20
|
-
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
21
|
-
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
22
|
-
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
23
|
-
|
|
24
|
-
interface CliOptions {
|
|
25
|
-
analyze?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const build = async (options?: CliOptions) => {
|
|
29
|
-
const webpackBuild = async (webpackConfig: Configuration, type?: string) => {
|
|
30
|
-
const compiler = webpack(webpackConfig);
|
|
31
|
-
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
let label = process.env.NODE_ENV || '';
|
|
34
|
-
if (type && type !== 'legacy') {
|
|
35
|
-
label += ` ${type}`;
|
|
36
|
-
}
|
|
37
|
-
logger.info(`Creating a ${label} build...`);
|
|
38
|
-
|
|
39
|
-
compiler.run((err, stats) => {
|
|
40
|
-
let messages: {
|
|
41
|
-
errors: any;
|
|
42
|
-
warnings: any;
|
|
43
|
-
};
|
|
44
|
-
if (!err) {
|
|
45
|
-
messages = formatWebpackMessages(
|
|
46
|
-
stats!.toJson({ all: false, warnings: true, errors: true }),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
if (messages.errors.length === 0) {
|
|
50
|
-
logger.info(`File sizes after ${label} build:\n`);
|
|
51
|
-
printFileSizesAfterBuild(
|
|
52
|
-
stats,
|
|
53
|
-
previousFileSizes,
|
|
54
|
-
outputPath,
|
|
55
|
-
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
56
|
-
WARN_AFTER_CHUNK_GZIP_SIZE,
|
|
57
|
-
);
|
|
58
|
-
logger.log();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// When using run or watch, call close and wait for it to finish before calling run or watch again.
|
|
63
|
-
// Concurrent compilations will corrupt the output files.
|
|
64
|
-
compiler.close(closeErr => {
|
|
65
|
-
if (closeErr) {
|
|
66
|
-
logger.error(closeErr);
|
|
67
|
-
}
|
|
68
|
-
if (err) {
|
|
69
|
-
reject(err);
|
|
70
|
-
} else {
|
|
71
|
-
if (messages.errors.length) {
|
|
72
|
-
reject(new Error(messages.errors.join('\n\n')));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
resolve({ warnings: messages.warnings });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
83
|
-
const resolvedConfig = useResolvedConfigContext();
|
|
84
|
-
const appContext = useAppContext();
|
|
85
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
86
|
-
|
|
87
|
-
manager.run(() => {
|
|
88
|
-
ResolvedConfigContext.set({ ...resolvedConfig, cliOptions: options });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const outputPath = appContext.distDirectory;
|
|
92
|
-
const previousFileSizes = await measureFileSizesBeforeBuild(outputPath);
|
|
93
|
-
fs.emptyDirSync(outputPath);
|
|
94
|
-
|
|
95
|
-
const buildConfigs = [];
|
|
96
|
-
|
|
97
|
-
buildConfigs.push({
|
|
98
|
-
type: 'legacy',
|
|
99
|
-
config: getWebpackConfig(WebpackConfigTarget.CLIENT)!,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
if (resolvedConfig.output.enableModernMode) {
|
|
103
|
-
buildConfigs.push({
|
|
104
|
-
type: 'modern',
|
|
105
|
-
config: getWebpackConfig(WebpackConfigTarget.MODERN)!,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (isUseSSRBundle(resolvedConfig)) {
|
|
110
|
-
buildConfigs.push({
|
|
111
|
-
type: 'ssr',
|
|
112
|
-
config: getWebpackConfig(WebpackConfigTarget.NODE)!,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
await (mountHook() as any).beforeBuild({
|
|
117
|
-
webpackConfigs: buildConfigs.map(({ config }) => config),
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
for (const buildConfig of buildConfigs) {
|
|
121
|
-
const { type: buildType, config } = buildConfig;
|
|
122
|
-
try {
|
|
123
|
-
await webpackBuild(config, buildType);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
printBuildError(error as Error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
await (mountHook() as any).afterBuild();
|
|
129
|
-
};
|
package/src/commands/deploy.ts
DELETED
package/src/commands/dev.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Configuration,
|
|
3
|
-
getWebpackConfig,
|
|
4
|
-
WebpackConfigTarget,
|
|
5
|
-
} from '@modern-js/webpack';
|
|
6
|
-
import {
|
|
7
|
-
fs,
|
|
8
|
-
logger,
|
|
9
|
-
HMR_SOCK_PATH,
|
|
10
|
-
clearConsole,
|
|
11
|
-
chalk,
|
|
12
|
-
isSSR,
|
|
13
|
-
} from '@modern-js/utils';
|
|
14
|
-
import {
|
|
15
|
-
useAppContext,
|
|
16
|
-
useResolvedConfigContext,
|
|
17
|
-
mountHook,
|
|
18
|
-
} from '@modern-js/core';
|
|
19
|
-
import { createCompiler } from '../utils/createCompiler';
|
|
20
|
-
import { createServer } from '../utils/createServer';
|
|
21
|
-
|
|
22
|
-
export const dev = async () => {
|
|
23
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
24
|
-
const appContext = useAppContext();
|
|
25
|
-
const userConfig = useResolvedConfigContext();
|
|
26
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
27
|
-
|
|
28
|
-
const { appDirectory, distDirectory, port } = appContext;
|
|
29
|
-
|
|
30
|
-
fs.emptyDirSync(distDirectory);
|
|
31
|
-
|
|
32
|
-
await (mountHook() as any).beforeDev();
|
|
33
|
-
|
|
34
|
-
const webpackConfigs = [
|
|
35
|
-
isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE),
|
|
36
|
-
getWebpackConfig(WebpackConfigTarget.CLIENT),
|
|
37
|
-
].filter(Boolean) as Configuration[];
|
|
38
|
-
|
|
39
|
-
const compiler = await createCompiler({
|
|
40
|
-
webpackConfigs,
|
|
41
|
-
userConfig,
|
|
42
|
-
appContext,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const app = await createServer({
|
|
46
|
-
dev: {
|
|
47
|
-
...{
|
|
48
|
-
client: {
|
|
49
|
-
port: port!.toString(),
|
|
50
|
-
overlay: false,
|
|
51
|
-
logging: 'none',
|
|
52
|
-
path: HMR_SOCK_PATH,
|
|
53
|
-
host: 'localhost',
|
|
54
|
-
},
|
|
55
|
-
dev: { writeToDisk: (file: string) => !file.includes('.hot-update.') },
|
|
56
|
-
hot: true,
|
|
57
|
-
liveReload: true,
|
|
58
|
-
port,
|
|
59
|
-
https: userConfig.dev.https,
|
|
60
|
-
},
|
|
61
|
-
...userConfig.tools.devServer,
|
|
62
|
-
},
|
|
63
|
-
compiler,
|
|
64
|
-
pwd: appDirectory,
|
|
65
|
-
config: userConfig as any,
|
|
66
|
-
plugins: appContext.plugins
|
|
67
|
-
.filter((p: any) => p.server)
|
|
68
|
-
.map((p: any) => p.server),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
app.listen(port, (err: Error) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
clearConsole();
|
|
77
|
-
|
|
78
|
-
logger.log(chalk.cyan(`Starting the development server...`));
|
|
79
|
-
});
|
|
80
|
-
};
|
package/src/commands/index.ts
DELETED
package/src/commands/start.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { logger, chalk } from '@modern-js/utils';
|
|
2
|
-
import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
3
|
-
import server from '@modern-js/server';
|
|
4
|
-
import { printInstructions } from '../utils/printInstructions';
|
|
5
|
-
|
|
6
|
-
export const start = async () => {
|
|
7
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
8
|
-
const appContext = useAppContext();
|
|
9
|
-
const userConfig = useResolvedConfigContext();
|
|
10
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
11
|
-
|
|
12
|
-
const { appDirectory, port } = appContext;
|
|
13
|
-
|
|
14
|
-
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
15
|
-
|
|
16
|
-
const app = await server({
|
|
17
|
-
pwd: appDirectory,
|
|
18
|
-
config: userConfig as any,
|
|
19
|
-
plugins: appContext.plugins
|
|
20
|
-
.filter((p: any) => p.server)
|
|
21
|
-
.map((p: any) => p.server),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
app.listen(port, async (err: Error) => {
|
|
25
|
-
if (err) {
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
await printInstructions(appContext, userConfig);
|
|
29
|
-
});
|
|
30
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { createPlugin, defineConfig, usePlugins, cli } from '@modern-js/core';
|
|
2
|
-
import { lifecycle } from './lifecycle';
|
|
3
|
-
import { i18n, localeKeys } from './locale';
|
|
4
|
-
import { getLocaleLanguage } from './utils/language';
|
|
5
|
-
import { start } from './commands/start';
|
|
6
|
-
import { dev } from './commands/dev';
|
|
7
|
-
|
|
8
|
-
export { defineConfig };
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
11
|
-
usePlugins([
|
|
12
|
-
require.resolve('@modern-js/plugin-analyze/cli'),
|
|
13
|
-
require.resolve('@modern-js/plugin-fast-refresh/cli'),
|
|
14
|
-
require.resolve('@modern-js/plugin-polyfill/cli'),
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export default createPlugin(
|
|
18
|
-
(() => {
|
|
19
|
-
const locale = getLocaleLanguage();
|
|
20
|
-
i18n.changeLanguage({ locale });
|
|
21
|
-
|
|
22
|
-
lifecycle();
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
commands({ program }: any) {
|
|
26
|
-
program
|
|
27
|
-
.command('dev')
|
|
28
|
-
.usage('[options]')
|
|
29
|
-
.description(i18n.t(localeKeys.command.dev.describe))
|
|
30
|
-
.option('-c --config <config>', i18n.t(localeKeys.command.dev.config))
|
|
31
|
-
.action(async () => {
|
|
32
|
-
await dev();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
program
|
|
36
|
-
.command('build')
|
|
37
|
-
.usage('[options]')
|
|
38
|
-
.description(i18n.t(localeKeys.command.build.describe))
|
|
39
|
-
.option('--analyze', i18n.t(localeKeys.command.build.analyze))
|
|
40
|
-
.action(async (options: any) => {
|
|
41
|
-
const { build } = await import('./commands/build');
|
|
42
|
-
await build(options);
|
|
43
|
-
// force exit after build.
|
|
44
|
-
// eslint-disable-next-line no-process-exit
|
|
45
|
-
process.exit(0);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
program
|
|
49
|
-
.command('start')
|
|
50
|
-
.usage('[options]')
|
|
51
|
-
.description(i18n.t(localeKeys.command.start.describe))
|
|
52
|
-
.action(async () => {
|
|
53
|
-
await start();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
program
|
|
57
|
-
.command('deploy')
|
|
58
|
-
.usage('[options]')
|
|
59
|
-
.description(i18n.t(localeKeys.command.deploy.describe))
|
|
60
|
-
.action(async (options: any) => {
|
|
61
|
-
const { build } = await import('./commands/build');
|
|
62
|
-
await build();
|
|
63
|
-
const { deploy } = await import('./commands/deploy');
|
|
64
|
-
await deploy(options);
|
|
65
|
-
// eslint-disable-next-line no-process-exit
|
|
66
|
-
process.exit(0);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
program
|
|
70
|
-
.command('new')
|
|
71
|
-
.usage('[options]')
|
|
72
|
-
.description(i18n.t(localeKeys.command.new.describe))
|
|
73
|
-
.option('-d, --debug', i18n.t(localeKeys.command.new.debug), false)
|
|
74
|
-
.option(
|
|
75
|
-
'-c, --config <config>',
|
|
76
|
-
i18n.t(localeKeys.command.new.config),
|
|
77
|
-
)
|
|
78
|
-
.option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag))
|
|
79
|
-
.option('--registry', i18n.t(localeKeys.command.new.registry))
|
|
80
|
-
.action(async (options: any) => {
|
|
81
|
-
const { MWANewAction } = await import('@modern-js/new-action');
|
|
82
|
-
await MWANewAction({ ...options, locale });
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
async fileChange() {
|
|
86
|
-
await cli.restart();
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}) as any,
|
|
90
|
-
{
|
|
91
|
-
post: [
|
|
92
|
-
'@modern-js/plugin-analyze',
|
|
93
|
-
'@modern-js/plugin-fast-refresh',
|
|
94
|
-
'@modern-js/plugin-ssr',
|
|
95
|
-
'@modern-js/plugin-state',
|
|
96
|
-
'@modern-js/plugin-router',
|
|
97
|
-
'@modern-js/plugin-polyfill',
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
);
|
package/src/lifecycle.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
|
|
2
|
-
import { registerHook } from '@modern-js/core';
|
|
3
|
-
|
|
4
|
-
import type { Compiler, Configuration, MultiCompiler } from '@modern-js/types';
|
|
5
|
-
|
|
6
|
-
export const beforeDev = createAsyncWorkflow();
|
|
7
|
-
|
|
8
|
-
export const afterDev = createAsyncWorkflow();
|
|
9
|
-
|
|
10
|
-
export const beforeCreateCompiler = createAsyncWorkflow<{
|
|
11
|
-
webpackConfigs: Configuration[];
|
|
12
|
-
}>();
|
|
13
|
-
|
|
14
|
-
export const afterCreateCompiler = createAsyncWorkflow<{
|
|
15
|
-
compiler: Compiler | MultiCompiler | undefined;
|
|
16
|
-
}>();
|
|
17
|
-
|
|
18
|
-
export const beforePrintInstructions =
|
|
19
|
-
createAsyncWaterfall<{ instructions: string }>();
|
|
20
|
-
|
|
21
|
-
export const beforeBuild = createAsyncWorkflow<{
|
|
22
|
-
webpackConfigs: Configuration[];
|
|
23
|
-
}>();
|
|
24
|
-
|
|
25
|
-
export const afterBuild = createAsyncWorkflow();
|
|
26
|
-
|
|
27
|
-
export const beforeDeploy = createAsyncWorkflow<Record<string, any>>();
|
|
28
|
-
|
|
29
|
-
export const afterDeploy = createAsyncWorkflow<Record<string, any>>();
|
|
30
|
-
|
|
31
|
-
export const lifecycle = () => {
|
|
32
|
-
registerHook({
|
|
33
|
-
beforeDev,
|
|
34
|
-
afterDev,
|
|
35
|
-
beforeCreateCompiler,
|
|
36
|
-
afterCreateCompiler,
|
|
37
|
-
beforePrintInstructions,
|
|
38
|
-
beforeBuild,
|
|
39
|
-
afterBuild,
|
|
40
|
-
beforeDeploy,
|
|
41
|
-
afterDeploy,
|
|
42
|
-
});
|
|
43
|
-
};
|
package/src/locale/en.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const EN_LOCALE = {
|
|
2
|
-
command: {
|
|
3
|
-
dev: {
|
|
4
|
-
describe: 'start dev server',
|
|
5
|
-
config: 'specify config file',
|
|
6
|
-
},
|
|
7
|
-
build: { describe: 'build application', analyze: 'analyze bundle' },
|
|
8
|
-
start: { describe: 'start server' },
|
|
9
|
-
deploy: { describe: 'deploy application' },
|
|
10
|
-
new: {
|
|
11
|
-
describe: 'generator runner for MWA project',
|
|
12
|
-
debug: 'using debug mode to log something',
|
|
13
|
-
config: 'set default generator config(json string)',
|
|
14
|
-
distTag: `use specified tag version for it's generator`,
|
|
15
|
-
registry: 'set npm registry url to run npm command',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
package/src/locale/index.ts
DELETED
package/src/locale/zh.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const ZH_LOCALE = {
|
|
2
|
-
command: {
|
|
3
|
-
dev: {
|
|
4
|
-
describe: '本地开发命令',
|
|
5
|
-
config: '制定配置文件路径',
|
|
6
|
-
},
|
|
7
|
-
build: { describe: '构建应用命令', analyze: '分析构建产物' },
|
|
8
|
-
start: { describe: '应用启动命令' },
|
|
9
|
-
deploy: { describe: '部署应用命令' },
|
|
10
|
-
new: {
|
|
11
|
-
describe: 'MWA 项目中中执行生成器',
|
|
12
|
-
debug: '开启 Debug 模式,打印调试日志信息',
|
|
13
|
-
config: '生成器运行默认配置(JSON 字符串)',
|
|
14
|
-
distTag: '生成器使用特殊的 npm Tag 版本',
|
|
15
|
-
registry: '生成器运行过程中定制 npm Registry',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import webpack, { Configuration, StatsCompilation } from 'webpack';
|
|
2
|
-
import { IAppContext, NormalizedConfig, mountHook } from '@modern-js/core';
|
|
3
|
-
import {
|
|
4
|
-
chalk,
|
|
5
|
-
logger,
|
|
6
|
-
formatWebpackMessages,
|
|
7
|
-
clearConsole,
|
|
8
|
-
} from '@modern-js/utils';
|
|
9
|
-
import { printInstructions } from './printInstructions';
|
|
10
|
-
|
|
11
|
-
const prettyTime = (stats: StatsCompilation) =>
|
|
12
|
-
Math.max(...(stats.children?.map(child => child.time || 0) || []));
|
|
13
|
-
|
|
14
|
-
export const createCompiler = async ({
|
|
15
|
-
webpackConfigs,
|
|
16
|
-
// TODO: params
|
|
17
|
-
userConfig,
|
|
18
|
-
appContext,
|
|
19
|
-
}: {
|
|
20
|
-
webpackConfigs: Configuration[];
|
|
21
|
-
userConfig: NormalizedConfig;
|
|
22
|
-
appContext: IAppContext;
|
|
23
|
-
}) => {
|
|
24
|
-
try {
|
|
25
|
-
await (mountHook() as any).beforeCreateCompiler({ webpackConfigs });
|
|
26
|
-
const compiler = webpack(webpackConfigs);
|
|
27
|
-
|
|
28
|
-
await (mountHook() as any).afterCreateCompiler({ compiler });
|
|
29
|
-
|
|
30
|
-
let isFirstCompile = true;
|
|
31
|
-
|
|
32
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
|
33
|
-
clearConsole();
|
|
34
|
-
logger.log('Compiling...');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
compiler.hooks.done.tap('done', async (stats: any) => {
|
|
38
|
-
clearConsole();
|
|
39
|
-
|
|
40
|
-
const statsData = stats.toJson({
|
|
41
|
-
all: false,
|
|
42
|
-
warnings: true,
|
|
43
|
-
errors: true,
|
|
44
|
-
timings: true,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const { errors, warnings } = formatWebpackMessages(statsData);
|
|
48
|
-
|
|
49
|
-
if (errors.length) {
|
|
50
|
-
logger.log(chalk.red(`Failed to compile.\n`));
|
|
51
|
-
logger.log(errors.join('\n\n'));
|
|
52
|
-
logger.log();
|
|
53
|
-
} else if (process.stdout.isTTY || isFirstCompile) {
|
|
54
|
-
await (mountHook() as any).afterDev();
|
|
55
|
-
if (warnings.length) {
|
|
56
|
-
logger.log(chalk.yellow(`Compiled with warnings.\n`));
|
|
57
|
-
logger.log(warnings.join('\n\n'));
|
|
58
|
-
logger.log();
|
|
59
|
-
} else {
|
|
60
|
-
logger.log(
|
|
61
|
-
chalk.green(
|
|
62
|
-
`Compiled successfully in ${prettyTime(statsData)} ms.\n`,
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
await printInstructions(appContext, userConfig);
|
|
67
|
-
}
|
|
68
|
-
// eslint-disable-next-line require-atomic-updates
|
|
69
|
-
isFirstCompile = false;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return compiler;
|
|
73
|
-
} catch (err) {
|
|
74
|
-
logger.log(chalk.red(`Failed to compile.`));
|
|
75
|
-
logger.log();
|
|
76
|
-
logger.log(err as any);
|
|
77
|
-
// eslint-disable-next-line no-process-exit
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Server, ModernServerOptions } from '@modern-js/server';
|
|
2
|
-
|
|
3
|
-
let server: Server;
|
|
4
|
-
|
|
5
|
-
export const createServer = async (options: ModernServerOptions) => {
|
|
6
|
-
if (server) {
|
|
7
|
-
await server.close();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line require-atomic-updates
|
|
11
|
-
server = new Server(options);
|
|
12
|
-
|
|
13
|
-
const app = await server.init();
|
|
14
|
-
|
|
15
|
-
return app;
|
|
16
|
-
};
|
package/src/utils/language.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
|
|
2
|
-
import { mountHook, IAppContext, NormalizedConfig } from '@modern-js/core';
|
|
3
|
-
|
|
4
|
-
export const printInstructions = async (
|
|
5
|
-
appContext: IAppContext,
|
|
6
|
-
config: NormalizedConfig,
|
|
7
|
-
) => {
|
|
8
|
-
let message = prettyInstructions(appContext, config);
|
|
9
|
-
|
|
10
|
-
if (isDev()) {
|
|
11
|
-
message += `\n${chalk.cyanBright(
|
|
12
|
-
[
|
|
13
|
-
`Note that the development build is not optimized.`,
|
|
14
|
-
`To create a production build, execute build command.`,
|
|
15
|
-
].join('\n'),
|
|
16
|
-
)}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// call beforePrintInstructions hook.
|
|
20
|
-
const { instructions } = await (mountHook() as any).beforePrintInstructions({
|
|
21
|
-
instructions: message,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
logger.log(instructions);
|
|
25
|
-
};
|