@modern-js/module-tools 1.5.7 → 1.6.0-alpha.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/js/modern/cli/build.js +5 -4
  3. package/dist/js/modern/commands/build.js +40 -27
  4. package/dist/js/modern/features/build/bundle/index.js +6 -0
  5. package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
  6. package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
  7. package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
  8. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
  9. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  10. package/dist/js/modern/features/build/bundleless/index.js +13 -0
  11. package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
  12. package/dist/js/modern/features/build/bundleless/style.js +266 -0
  13. package/dist/js/modern/features/build/constants.js +94 -59
  14. package/dist/js/modern/features/build/error.js +150 -0
  15. package/dist/js/modern/features/build/index.js +84 -19
  16. package/dist/js/modern/features/build/legacy-constants.js +99 -0
  17. package/dist/js/modern/features/build/normalize.js +293 -0
  18. package/dist/js/modern/features/build/types.js +0 -0
  19. package/dist/js/modern/features/build/utils.js +29 -137
  20. package/dist/js/modern/index.js +3 -1
  21. package/dist/js/modern/locale/en.js +5 -3
  22. package/dist/js/modern/locale/zh.js +5 -3
  23. package/dist/js/modern/schema/build-config.js +104 -0
  24. package/dist/js/modern/schema/index.js +2 -1
  25. package/dist/js/modern/schema/output.js +18 -9
  26. package/dist/js/modern/schema/source.js +2 -10
  27. package/dist/js/modern/schema/tools.js +6 -0
  28. package/dist/js/modern/schema/types.js +0 -0
  29. package/dist/js/modern/utils/babel.js +4 -1
  30. package/dist/js/modern/utils/constants.js +3 -0
  31. package/dist/js/node/cli/build.js +5 -4
  32. package/dist/js/node/commands/build.js +50 -29
  33. package/dist/js/node/features/build/bundle/index.js +17 -0
  34. package/dist/js/node/features/build/bundle/runRollup.js +174 -0
  35. package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
  36. package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
  37. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
  38. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  39. package/dist/js/node/features/build/bundleless/index.js +26 -0
  40. package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
  41. package/dist/js/node/features/build/bundleless/style.js +299 -0
  42. package/dist/js/node/features/build/constants.js +115 -67
  43. package/dist/js/node/features/build/error.js +175 -0
  44. package/dist/js/node/features/build/index.js +92 -19
  45. package/dist/js/node/features/build/legacy-constants.js +107 -0
  46. package/dist/js/node/features/build/normalize.js +322 -0
  47. package/dist/js/node/features/build/types.js +0 -0
  48. package/dist/js/node/features/build/utils.js +31 -145
  49. package/dist/js/node/index.js +5 -1
  50. package/dist/js/node/locale/en.js +5 -3
  51. package/dist/js/node/locale/zh.js +5 -3
  52. package/dist/js/node/schema/build-config.js +113 -0
  53. package/dist/js/node/schema/index.js +3 -1
  54. package/dist/js/node/schema/output.js +20 -9
  55. package/dist/js/node/schema/source.js +2 -10
  56. package/dist/js/node/schema/tools.js +13 -0
  57. package/dist/js/node/schema/types.js +0 -0
  58. package/dist/js/node/utils/babel.js +4 -1
  59. package/dist/js/node/utils/constants.js +11 -0
  60. package/dist/types/cli/build.d.ts +1 -1
  61. package/dist/types/cli/new.d.ts +1 -1
  62. package/dist/types/commands/build.d.ts +12 -12
  63. package/dist/types/features/build/bundle/index.d.ts +3 -0
  64. package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
  65. package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
  66. package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
  67. package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
  68. package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
  69. package/dist/types/features/build/bundleless/index.d.ts +4 -0
  70. package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
  71. package/dist/types/features/build/bundleless/style.d.ts +25 -0
  72. package/dist/types/features/build/constants.d.ts +17 -13
  73. package/dist/types/features/build/error.d.ts +33 -0
  74. package/dist/types/features/build/index.d.ts +4 -3
  75. package/dist/types/features/build/legacy-constants.d.ts +8 -0
  76. package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
  77. package/dist/types/features/build/normalize.d.ts +18 -0
  78. package/dist/types/features/build/types.d.ts +15 -0
  79. package/dist/types/features/build/utils.d.ts +9 -31
  80. package/dist/types/locale/en.d.ts +2 -0
  81. package/dist/types/locale/index.d.ts +4 -0
  82. package/dist/types/locale/zh.d.ts +2 -0
  83. package/dist/types/schema/build-config.d.ts +179 -0
  84. package/dist/types/schema/index.d.ts +166 -18
  85. package/dist/types/schema/output.d.ts +170 -10
  86. package/dist/types/schema/source.d.ts +2 -11
  87. package/dist/types/schema/tools.d.ts +6 -0
  88. package/dist/types/schema/types.d.ts +45 -0
  89. package/dist/types/types.d.ts +29 -28
  90. package/dist/types/utils/babel.d.ts +3 -2
  91. package/dist/types/utils/constants.d.ts +2 -0
  92. package/dist/types/utils/logger.d.ts +2 -0
  93. package/package.json +28 -15
  94. package/dist/js/modern/features/build/build-watch.js +0 -101
  95. package/dist/js/modern/features/build/build.js +0 -123
  96. package/dist/js/modern/tasks/build-source-code.js +0 -207
  97. package/dist/js/modern/tasks/build-style.js +0 -168
  98. package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
  99. package/dist/js/modern/tasks/build-watch-style.js +0 -215
  100. package/dist/js/modern/tasks/constants.js +0 -1
  101. package/dist/js/node/features/build/build-watch.js +0 -121
  102. package/dist/js/node/features/build/build.js +0 -143
  103. package/dist/js/node/tasks/build-source-code.js +0 -233
  104. package/dist/js/node/tasks/build-style.js +0 -183
  105. package/dist/js/node/tasks/build-watch-source-code.js +0 -173
  106. package/dist/js/node/tasks/build-watch-style.js +0 -232
  107. package/dist/js/node/tasks/constants.js +0 -8
  108. package/dist/types/features/build/build-watch.d.ts +0 -3
  109. package/dist/types/features/build/build.d.ts +0 -3
  110. package/dist/types/tasks/build-source-code.d.ts +0 -25
  111. package/dist/types/tasks/build-style.d.ts +0 -1
  112. package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
  113. package/dist/types/tasks/build-watch-style.d.ts +0 -1
  114. package/dist/types/tasks/constants.d.ts +0 -1
  115. package/dist/types/tasks/copy-assets.d.ts +0 -1
  116. package/dist/types/tasks/generator-dts/index.d.ts +0 -1
@@ -1,168 +0,0 @@
1
- import * as path from 'path';
2
- import { fs, glob, Import } from '@modern-js/utils';
3
- const cssConfig = Import.lazy('@modern-js/css-config', require);
4
- const core = Import.lazy('@modern-js/core', require);
5
- const compiler = Import.lazy('@modern-js/style-compiler', require);
6
- const hooks = Import.lazy('../hooks', require);
7
- const STYLE_DIRS = 'styles';
8
- const SRC_STYLE_DIRS = 'src';
9
-
10
- const checkStylesDirExist = option => {
11
- const {
12
- appDirectory
13
- } = option;
14
- return fs.existsSync(path.join(appDirectory, STYLE_DIRS));
15
- };
16
-
17
- const generatorFileOrLogError = (result, successMessage = '') => {
18
- if (result.code === 0 && result.dists.length > 0) {
19
- for (const file of result.dists) {
20
- fs.ensureFileSync(file.filename);
21
- fs.writeFileSync(file.filename, file.content);
22
- }
23
-
24
- if (successMessage) {
25
- console.info(successMessage);
26
- }
27
- } else {
28
- for (const file of result.errors) {
29
- console.error(file.error);
30
- }
31
- }
32
- };
33
-
34
- const getPostcssOption = (appDirectory, modernConfig) => {
35
- var _postcssOption$postcs;
36
-
37
- const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
38
- return {
39
- plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
40
- enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
41
- options: {}
42
- };
43
- };
44
-
45
- const copyOriginStyleFiles = ({
46
- targetDir,
47
- outputDir
48
- }) => {
49
- const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
50
-
51
- if (styleFiles.length > 0) {
52
- fs.ensureDirSync(outputDir);
53
- }
54
-
55
- for (const styleFile of styleFiles) {
56
- const file = path.relative(targetDir, styleFile);
57
- fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
58
- fs.copyFileSync(styleFile, path.join(outputDir, file));
59
- }
60
- };
61
-
62
- const taskMain = async ({
63
- modernConfig,
64
- appContext
65
- }) => {
66
- const {
67
- assetsPath = 'styles',
68
- path: outputPath = 'dist',
69
- jsPath = 'js'
70
- } = modernConfig.output;
71
- const {
72
- appDirectory
73
- } = appContext;
74
- const lessOption = await core.mountHook().moduleLessConfig({
75
- modernConfig
76
- }, {
77
- onLast: async _ => undefined
78
- });
79
- const sassOption = await core.mountHook().moduleSassConfig({
80
- modernConfig
81
- }, {
82
- onLast: async _ => undefined
83
- });
84
- const tailwindPlugin = await core.mountHook().moduleTailwindConfig({
85
- modernConfig
86
- }, {
87
- onLast: async _ => undefined
88
- });
89
- const postcssOption = getPostcssOption(appDirectory, modernConfig);
90
-
91
- if (tailwindPlugin) {
92
- var _postcssOption$plugin;
93
-
94
- (_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
95
- }
96
-
97
- const {
98
- importStyle
99
- } = modernConfig.output;
100
- const existStylesDir = checkStylesDirExist({
101
- appDirectory
102
- }); // 编译 styles 目录样式
103
-
104
- if (existStylesDir) {
105
- const styleResult = await compiler.styleCompiler({
106
- projectDir: appDirectory,
107
- stylesDir: path.resolve(appDirectory, STYLE_DIRS),
108
- outDir: path.join(appDirectory, outputPath, assetsPath),
109
- enableVirtualDist: true,
110
- compilerOption: {
111
- less: lessOption,
112
- sass: sassOption,
113
- postcss: postcssOption
114
- }
115
- });
116
- generatorFileOrLogError(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
117
- } // 编译 src 内的样式代码
118
-
119
-
120
- const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
121
- const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
122
-
123
- if (importStyle === 'compiled-code') {
124
- const srcStyleResult = await compiler.styleCompiler({
125
- projectDir: appDirectory,
126
- stylesDir: srcDir,
127
- outDir: outputDirToSrc,
128
- enableVirtualDist: true,
129
- compilerOption: {
130
- less: lessOption,
131
- sass: sassOption,
132
- postcss: postcssOption
133
- }
134
- });
135
- generatorFileOrLogError(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
136
- } else {
137
- copyOriginStyleFiles({
138
- targetDir: srcDir,
139
- outputDir: outputDirToSrc
140
- });
141
- }
142
- };
143
-
144
- (async () => {
145
- let options;
146
-
147
- if (process.env.CORE_INIT_OPTION_FILE) {
148
- ({
149
- options
150
- } = require(process.env.CORE_INIT_OPTION_FILE));
151
- }
152
-
153
- hooks.buildLifeCycle();
154
- const {
155
- resolved: modernConfig,
156
- appContext
157
- } = await core.cli.init([], options);
158
- await core.manager.run(async () => {
159
- try {
160
- await taskMain({
161
- modernConfig,
162
- appContext
163
- });
164
- } catch (e) {
165
- console.error(e.toString());
166
- }
167
- });
168
- })();
@@ -1,161 +0,0 @@
1
- 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; }
2
-
3
- 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; }
4
-
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
-
7
- import { Import, fs } from '@modern-js/utils';
8
- import { initEnv } from "../utils/init-env";
9
- const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
10
- const logger = Import.lazy('../features/build/logger', require);
11
- const ts = Import.lazy('../utils/tsconfig', require);
12
- const babel = Import.lazy('../utils/babel', require);
13
- const core = Import.lazy('@modern-js/core', require);
14
- const argv = Import.lazy('process.argv', require);
15
-
16
- const generatorRealFiles = virtualDists => {
17
- for (const virtualDist of virtualDists) {
18
- const {
19
- distPath,
20
- code,
21
- sourcemap,
22
- sourceMapPath
23
- } = virtualDist;
24
- fs.ensureFileSync(distPath);
25
- fs.writeFileSync(distPath, code);
26
-
27
- if (sourcemap.length > 0) {
28
- fs.ensureFileSync(sourceMapPath);
29
- fs.writeFileSync(sourceMapPath, sourcemap);
30
- }
31
- }
32
- };
33
-
34
- const runBabelCompiler = async (config, modernConfig) => {
35
- const {
36
- tsconfigPath
37
- } = config;
38
- const babelConfig = babel.resolveBabelConfig(config.appDirectory, modernConfig, {
39
- sourceAbsDir: config.srcRootDir,
40
- tsconfigPath,
41
- syntax: config.syntax,
42
- type: config.type
43
- });
44
- const tsconfig = ts.readTsConfig(tsconfigPath || '', {});
45
- const isTs = Boolean(tsconfig);
46
-
47
- const getExts = isTsProject => {
48
- // TODO: 是否受控tsconfig.json 里的jsx配置
49
- let exts = [];
50
-
51
- if (isTsProject) {
52
- var _tsconfig$compilerOpt;
53
-
54
- exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
55
- } else {
56
- exts = ['.js', '.jsx'];
57
- }
58
-
59
- return exts;
60
- };
61
-
62
- const emitter = await babelCompiler.compiler({
63
- enableVirtualDist: true,
64
- quiet: true,
65
- enableWatch: true,
66
- rootDir: config.srcRootDir,
67
- distDir: config.distDir,
68
- watchDir: config.srcRootDir,
69
- extensions: getExts(isTs),
70
- ignore: ['*.d.ts']
71
- }, _objectSpread(_objectSpread({}, babelConfig), {}, {
72
- sourceMaps: config.sourceMaps
73
- }));
74
- emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
75
- console.info(logger.clearFlag, `Compiling...`);
76
- });
77
- emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
78
- if (result.code === 1) {
79
- console.error(logger.clearFlag);
80
- console.error(result.message);
81
-
82
- for (const detail of result.messageDetails || []) {
83
- console.error(detail.content);
84
- }
85
- } else {
86
- generatorRealFiles(result.virtualDists);
87
- console.info(logger.clearFlag, '[Babel Compiler]: Successfully');
88
- }
89
- });
90
- emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
91
- if (result.code === 1) {
92
- var _result$virtualDists;
93
-
94
- console.error(logger.clearFlag);
95
- console.error(result.message);
96
-
97
- for (const detail of result.messageDetails || []) {
98
- console.error(detail.content);
99
- }
100
-
101
- if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
102
- generatorRealFiles(result.virtualDists);
103
- }
104
- } else {
105
- generatorRealFiles(result.virtualDists);
106
- console.info(result.message);
107
- }
108
- });
109
- await emitter.watch();
110
- };
111
-
112
- const buildSourceCode = async (config, modernConfig) => {
113
- const {
114
- compiler
115
- } = config;
116
-
117
- if (compiler === 'babel') {
118
- await runBabelCompiler(config, modernConfig);
119
- }
120
- };
121
-
122
- const taskMain = async ({
123
- modernConfig
124
- }) => {
125
- const processArgv = argv(process.argv.slice(2));
126
- const config = processArgv({
127
- srcRootDir: `${process.cwd()}/src`,
128
- distDir: '',
129
- compiler: 'babel',
130
- appDirectory: '',
131
- sourceMaps: false,
132
- tsconfigPath: '',
133
- syntax: 'es5',
134
- type: 'module'
135
- });
136
- process.env.BUILD_FORMAT = initEnv(config);
137
- await buildSourceCode(config, modernConfig);
138
- };
139
-
140
- (async () => {
141
- let options;
142
-
143
- if (process.env.CORE_INIT_OPTION_FILE) {
144
- ({
145
- options
146
- } = require(process.env.CORE_INIT_OPTION_FILE));
147
- }
148
-
149
- const {
150
- resolved
151
- } = await core.cli.init([], options);
152
- await core.manager.run(async () => {
153
- try {
154
- await taskMain({
155
- modernConfig: resolved
156
- });
157
- } catch (e) {
158
- console.error(e);
159
- }
160
- });
161
- })();
@@ -1,215 +0,0 @@
1
- import * as path from 'path';
2
- import { fs, glob, watch, WatchChangeType, Import } from '@modern-js/utils';
3
- const logger = Import.lazy('../features/build/logger', require);
4
- const cssConfig = Import.lazy('@modern-js/css-config', require);
5
- const hooks = Import.lazy('../hooks', require);
6
- const core = Import.lazy('@modern-js/core', require);
7
- const compiler = Import.lazy('@modern-js/style-compiler', require);
8
- const STYLE_DIRS = 'styles';
9
- const SRC_STYLE_DIRS = 'src';
10
-
11
- const checkStylesDirExist = option => {
12
- const {
13
- appDirectory
14
- } = option;
15
- return fs.existsSync(path.join(appDirectory, STYLE_DIRS));
16
- };
17
-
18
- const generatorFileAndReturnLog = (result, successMessage = '') => {
19
- if (result.code === 0) {
20
- for (const file of result.dists) {
21
- fs.ensureFileSync(file.filename);
22
- fs.writeFileSync(file.filename, file.content);
23
- }
24
-
25
- return successMessage;
26
- } else {
27
- return result.errors.join('\n');
28
- }
29
- };
30
-
31
- const getPostcssOption = (appDirectory, modernConfig) => {
32
- var _postcssOption$postcs;
33
-
34
- const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
35
- return {
36
- plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
37
- enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
38
- options: {}
39
- };
40
- };
41
-
42
- const copyOriginStyleFiles = ({
43
- targetDir,
44
- outputDir
45
- }) => {
46
- const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
47
-
48
- if (styleFiles.length > 0) {
49
- fs.ensureDirSync(outputDir);
50
- }
51
-
52
- for (const styleFile of styleFiles) {
53
- const file = path.relative(targetDir, styleFile);
54
- fs.ensureFileSync(path.join(outputDir, file));
55
- fs.copyFileSync(styleFile, path.join(outputDir, file));
56
- }
57
- };
58
-
59
- const logCompilerMessage = compilerMessage => {
60
- console.info(logger.clearFlag);
61
- console.info(compilerMessage.src);
62
- console.info(compilerMessage.styles);
63
- };
64
-
65
- const taskMain = async ({
66
- modernConfig,
67
- appContext
68
- }) => {
69
- const {
70
- assetsPath = 'styles',
71
- path: outputPath = 'dist',
72
- jsPath = 'js',
73
- importStyle
74
- } = modernConfig.output;
75
- const {
76
- appDirectory
77
- } = appContext;
78
- const lessOption = await core.mountHook().moduleLessConfig({
79
- modernConfig
80
- }, {
81
- onLast: async _ => null
82
- });
83
- const sassOption = await core.mountHook().moduleSassConfig({
84
- modernConfig
85
- }, {
86
- onLast: async _ => null
87
- });
88
- const postcssOption = getPostcssOption(appDirectory, modernConfig);
89
- const existStylesDir = checkStylesDirExist({
90
- appDirectory
91
- });
92
- const compilerMessage = {
93
- src: '',
94
- styles: ''
95
- }; // 编译 styles 目录样式
96
-
97
- let styleEmitter = null;
98
-
99
- if (existStylesDir) {
100
- styleEmitter = compiler.styleCompiler({
101
- watch: true,
102
- projectDir: appDirectory,
103
- stylesDir: path.resolve(appDirectory, STYLE_DIRS),
104
- outDir: path.join(appDirectory, outputPath, assetsPath),
105
- enableVirtualDist: true,
106
- compilerOption: {
107
- less: lessOption,
108
- sass: sassOption,
109
- postcss: postcssOption
110
- }
111
- });
112
- styleEmitter.on(compiler.BuildWatchEvent.firstCompiler, styleResult => {
113
- compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
114
- logCompilerMessage(compilerMessage);
115
- });
116
- styleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
117
- compilerMessage.styles = `[${assetsPath}] Compiling...`;
118
- logCompilerMessage(compilerMessage);
119
- });
120
- styleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, styleResult => {
121
- compilerMessage.styles = generatorFileAndReturnLog(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
122
- logCompilerMessage(compilerMessage);
123
- }); // await styleEmitter.watch();
124
- } // 编译 src 内的样式代码
125
-
126
-
127
- const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
128
- const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
129
-
130
- if (importStyle === 'compiled-code') {
131
- compilerMessage.src = `[src] Compiling`;
132
- const srcStyleEmitter = compiler.styleCompiler({
133
- watch: true,
134
- projectDir: appDirectory,
135
- stylesDir: srcDir,
136
- outDir: outputDirToSrc,
137
- enableVirtualDist: true,
138
- compilerOption: {
139
- less: lessOption,
140
- sass: sassOption,
141
- postcss: postcssOption
142
- }
143
- });
144
- srcStyleEmitter.on(compiler.BuildWatchEvent.firstCompiler, srcStyleResult => {
145
- compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
146
- logCompilerMessage(compilerMessage);
147
- });
148
- srcStyleEmitter.on(compiler.BuildWatchEvent.compilering, () => {
149
- compilerMessage.src = `[src] Compiling`;
150
- logCompilerMessage(compilerMessage);
151
- });
152
- srcStyleEmitter.on(compiler.BuildWatchEvent.watchingCompiler, srcStyleResult => {
153
- compilerMessage.src = generatorFileAndReturnLog(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
154
- logCompilerMessage(compilerMessage);
155
- });
156
- styleEmitter && (await styleEmitter.watch());
157
- await srcStyleEmitter.watch();
158
- } else {
159
- compilerMessage.src = `['src' dir] Copying in progress`;
160
- styleEmitter && (await styleEmitter.watch());
161
- logCompilerMessage(compilerMessage);
162
- copyOriginStyleFiles({
163
- targetDir: srcDir,
164
- outputDir: outputDirToSrc
165
- });
166
- compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
167
- logCompilerMessage(compilerMessage);
168
- watch(`${srcDir}/**/*.{css,less,sass,scss}`, ({
169
- changeType,
170
- changedFilePath
171
- }) => {
172
- compilerMessage.src = `['src' dir] Copying in progress`;
173
- logCompilerMessage(compilerMessage);
174
-
175
- if (changeType === WatchChangeType.UNLINK) {
176
- const removeFile = path.normalize(`${outputDirToSrc}/${path.relative(srcDir, changedFilePath)}`);
177
- fs.removeSync(removeFile);
178
- } else {
179
- copyOriginStyleFiles({
180
- targetDir: srcDir,
181
- outputDir: outputDirToSrc
182
- });
183
- }
184
-
185
- compilerMessage.src = `[Style Compiler] Successfully for 'src' dir`;
186
- logCompilerMessage(compilerMessage);
187
- });
188
- }
189
- };
190
-
191
- (async () => {
192
- let options;
193
-
194
- if (process.env.CORE_INIT_OPTION_FILE) {
195
- ({
196
- options
197
- } = require(process.env.CORE_INIT_OPTION_FILE));
198
- }
199
-
200
- hooks.buildLifeCycle();
201
- const {
202
- resolved: modernConfig,
203
- appContext
204
- } = await core.cli.init([], options);
205
- await core.manager.run(async () => {
206
- try {
207
- await taskMain({
208
- modernConfig,
209
- appContext
210
- });
211
- } catch (e) {
212
- console.error(e);
213
- }
214
- });
215
- })();
@@ -1 +0,0 @@
1
- export const tempTsconfigName = './tsconfig.temp.json';
@@ -1,121 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildInWatchMode = void 0;
7
-
8
- var path = _interopRequireWildcard(require("path"));
9
-
10
- var os = _interopRequireWildcard(require("os"));
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- 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; }
17
-
18
- const lg = _utils.Import.lazy('./logger', require);
19
-
20
- const pMap = _utils.Import.lazy('p-map', require);
21
-
22
- const utils = _utils.Import.lazy('./utils', require);
23
-
24
- const constants = _utils.Import.lazy('./constants', require);
25
-
26
- const buildInWatchMode = async (api, config, _) => {
27
- const {
28
- appDirectory
29
- } = api.useAppContext();
30
- const {
31
- sourceDir,
32
- enableTscCompiler
33
- } = config;
34
- const srcRootDir = path.join(appDirectory, sourceDir);
35
- const concurrency = os.cpus().length;
36
- const lm = new lg.LoggerManager();
37
- const codeLog = lm.createLoggerText({
38
- title: constants.runBabelCompilerTitle
39
- });
40
- const dtsLog = lm.createLoggerText({
41
- title: constants.runTscWatchTitle
42
- });
43
- const styleLog = lm.createLoggerText({
44
- title: constants.runStyleCompilerTitle
45
- });
46
- const copyLog = lm.createLoggerText({
47
- title: 'Copy Log:'
48
- });
49
- const initCodeMapper = utils.getCodeInitMapper(api, config);
50
- const taskMapper = [...utils.getCodeMapper(api, {
51
- logger: codeLog,
52
- taskPath: require.resolve("../../tasks/build-watch-source-code"),
53
- config,
54
- willCompilerDirOrFile: sourceDir,
55
- initMapper: initCodeMapper,
56
- srcRootDir
57
- }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
58
- logger: styleLog,
59
- taskPath: require.resolve("../../tasks/build-watch-style")
60
- }, {
61
- logger: copyLog,
62
- taskPath: require.resolve("../../tasks/copy-assets"),
63
- params: ['--watch']
64
- }];
65
- lm.on('data', () => {
66
- console.info(constants.clearFlag);
67
- enableTscCompiler && console.info(dtsLog.value);
68
- console.info(codeLog.value);
69
- console.info(styleLog.value);
70
- });
71
- await pMap(taskMapper, async ({
72
- logger,
73
- taskPath,
74
- params
75
- }) => {
76
- const childProcess = _utils.execa.node(taskPath, params, {
77
- stdio: 'pipe'
78
- });
79
-
80
- if (logger === codeLog) {
81
- lm.addStdout(logger, childProcess.stdout, {
82
- event: {
83
- error: true,
84
- data: true
85
- } // colors: { data: s => s },
86
-
87
- });
88
- lm.addStderr(logger, childProcess.stderr);
89
- }
90
-
91
- if (logger === dtsLog) {
92
- lm.addStdout(logger, childProcess.stdout, {
93
- event: {
94
- data: true,
95
- error: true
96
- },
97
- colors: {
98
- // tsc 的log信息无论是错误还是正确都是从 data event 中获取到的
99
- data: s => s
100
- }
101
- });
102
- }
103
-
104
- if (logger === styleLog || logger === copyLog) {
105
- lm.addStdout(logger, childProcess.stdout, {
106
- event: {
107
- error: true,
108
- data: true
109
- } // colors: { data: s => s },
110
-
111
- });
112
- lm.addStderr(logger, childProcess.stderr);
113
- }
114
-
115
- await childProcess;
116
- }, {
117
- concurrency
118
- });
119
- };
120
-
121
- exports.buildInWatchMode = buildInWatchMode;