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