@modern-js/module-tools 1.5.8 → 1.6.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 +41 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -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 -56
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -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 +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- 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 +111 -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/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -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 -56
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -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 +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +20 -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 +120 -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/js/node/utils/copy.js +1 -1
- package/dist/types/cli/build.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 +12 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/normalize.d.ts +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- 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 +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -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 +46 -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/package.json +23 -9
- 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 -208
- package/dist/js/modern/tasks/build-style.js +0 -169
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
- package/dist/js/modern/tasks/build-watch-style.js +0 -216
- 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 -234
- package/dist/js/node/tasks/build-style.js +0 -184
- package/dist/js/node/tasks/build-watch-source-code.js +0 -174
- package/dist/js/node/tasks/build-watch-style.js +0 -233
- 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,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getWillCompilerCode = exports.buildSourceCode = exports.Compiler = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
|
-
var _initEnv = require("../utils/init-env");
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
|
|
19
|
-
|
|
20
|
-
const argv = _utils.Import.lazy('process.argv', require);
|
|
21
|
-
|
|
22
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
23
|
-
|
|
24
|
-
const bc = _utils.Import.lazy('../utils/babel', require);
|
|
25
|
-
|
|
26
|
-
const ts = _utils.Import.lazy('../utils/tsconfig', require);
|
|
27
|
-
|
|
28
|
-
let Compiler;
|
|
29
|
-
exports.Compiler = Compiler;
|
|
30
|
-
|
|
31
|
-
(function (Compiler) {
|
|
32
|
-
Compiler[Compiler["babel"] = 0] = "babel";
|
|
33
|
-
Compiler[Compiler["esbuild"] = 1] = "esbuild";
|
|
34
|
-
Compiler[Compiler["swc"] = 2] = "swc";
|
|
35
|
-
})(Compiler || (exports.Compiler = Compiler = {}));
|
|
36
|
-
|
|
37
|
-
const runBabelCompiler = async (willCompilerFiles, config, babelConfig = {}) => {
|
|
38
|
-
const {
|
|
39
|
-
srcRootDir,
|
|
40
|
-
distDir
|
|
41
|
-
} = config; // TODO: 判断lynx模式下,修改distFileExtMap: {'js': 'js', 'jsx': 'jsx', 'ts': 'js', 'tsx': 'jsx'}
|
|
42
|
-
|
|
43
|
-
return babelCompiler.compiler({
|
|
44
|
-
quiet: true,
|
|
45
|
-
enableVirtualDist: true,
|
|
46
|
-
rootDir: srcRootDir,
|
|
47
|
-
filenames: willCompilerFiles,
|
|
48
|
-
distDir,
|
|
49
|
-
ignore: ['*.d.ts']
|
|
50
|
-
}, babelConfig);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const getWillCompilerCode = (srcDirOrFile, option) => {
|
|
54
|
-
const {
|
|
55
|
-
tsconfig,
|
|
56
|
-
isTsProject
|
|
57
|
-
} = option; // 如果是一个文件路径,则直接返回
|
|
58
|
-
|
|
59
|
-
if (_utils.fs.existsSync(srcDirOrFile) && _utils.fs.lstatSync(srcDirOrFile).isFile()) {
|
|
60
|
-
return [srcDirOrFile];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const getExts = isTs => {
|
|
64
|
-
// TODO: 是否受控tsconfig.json 里的jsx配置
|
|
65
|
-
let exts = [];
|
|
66
|
-
|
|
67
|
-
if (isTs) {
|
|
68
|
-
var _tsconfig$compilerOpt;
|
|
69
|
-
|
|
70
|
-
exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
|
|
71
|
-
} else {
|
|
72
|
-
exts = ['.js', '.jsx'];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return exts;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const exts = getExts(isTsProject);
|
|
79
|
-
const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
|
|
80
|
-
|
|
81
|
-
const files = _utils.glob.sync(globPattern, {
|
|
82
|
-
ignore: [`${srcDirOrFile}/**/*.d.ts`],
|
|
83
|
-
absolute: true
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return files;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
exports.getWillCompilerCode = getWillCompilerCode;
|
|
90
|
-
|
|
91
|
-
const buildSourceCode = async config => {
|
|
92
|
-
const {
|
|
93
|
-
compiler,
|
|
94
|
-
willCompilerDirOrFile,
|
|
95
|
-
tsconfigPath,
|
|
96
|
-
sourceMaps,
|
|
97
|
-
babelConfig
|
|
98
|
-
} = config;
|
|
99
|
-
const tsconfig = ts.readTsConfig(tsconfigPath);
|
|
100
|
-
const willCompilerFiles = getWillCompilerCode(willCompilerDirOrFile, {
|
|
101
|
-
tsconfig,
|
|
102
|
-
isTsProject: Boolean(tsconfig)
|
|
103
|
-
});
|
|
104
|
-
let distSet = null;
|
|
105
|
-
|
|
106
|
-
if (compiler === Compiler.babel) {
|
|
107
|
-
distSet = await runBabelCompiler(willCompilerFiles, config, _objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
108
|
-
sourceMaps
|
|
109
|
-
}));
|
|
110
|
-
} else {
|
|
111
|
-
distSet = {
|
|
112
|
-
code: 1,
|
|
113
|
-
message: 'no compiler'
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return distSet;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
exports.buildSourceCode = buildSourceCode;
|
|
121
|
-
|
|
122
|
-
const generatorRealFiles = virtualDists => {
|
|
123
|
-
for (const virtualDist of virtualDists) {
|
|
124
|
-
const {
|
|
125
|
-
distPath,
|
|
126
|
-
code,
|
|
127
|
-
sourcemap,
|
|
128
|
-
sourceMapPath
|
|
129
|
-
} = virtualDist;
|
|
130
|
-
|
|
131
|
-
_utils.fs.ensureFileSync(distPath);
|
|
132
|
-
|
|
133
|
-
_utils.fs.writeFileSync(distPath, code);
|
|
134
|
-
|
|
135
|
-
if (sourcemap.length > 0) {
|
|
136
|
-
_utils.fs.ensureFileSync(sourceMapPath);
|
|
137
|
-
|
|
138
|
-
_utils.fs.writeFileSync(sourceMapPath, sourcemap);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const defaultConfig = {
|
|
144
|
-
srcRootDir: `${process.cwd()}/src`,
|
|
145
|
-
willCompilerDirOrFile: `${process.cwd()}/src`,
|
|
146
|
-
distDir: './dist/js/temp',
|
|
147
|
-
compiler: 'babel',
|
|
148
|
-
appDirectory: '',
|
|
149
|
-
sourceMaps: false,
|
|
150
|
-
tsconfigPath: '',
|
|
151
|
-
syntax: 'es5',
|
|
152
|
-
type: 'module',
|
|
153
|
-
watch: false
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const taskMain = async ({
|
|
157
|
-
modernConfig
|
|
158
|
-
}) => {
|
|
159
|
-
// Execution of the script's parameter handling and related required configuration acquisition
|
|
160
|
-
const processArgv = argv(process.argv.slice(2));
|
|
161
|
-
const config = processArgv(defaultConfig);
|
|
162
|
-
process.env.BUILD_FORMAT = (0, _initEnv.initEnv)(config);
|
|
163
|
-
const compiler = Compiler.babel; // Currently, only babel is supported.
|
|
164
|
-
|
|
165
|
-
const babelConfig = bc.resolveBabelConfig(config.appDirectory, modernConfig, {
|
|
166
|
-
sourceAbsDir: config.srcRootDir,
|
|
167
|
-
tsconfigPath: config.tsconfigPath,
|
|
168
|
-
syntax: config.syntax,
|
|
169
|
-
type: config.type
|
|
170
|
-
});
|
|
171
|
-
const {
|
|
172
|
-
code,
|
|
173
|
-
message,
|
|
174
|
-
messageDetails,
|
|
175
|
-
virtualDists = []
|
|
176
|
-
} = await buildSourceCode({
|
|
177
|
-
distDir: config.distDir,
|
|
178
|
-
srcRootDir: config.srcRootDir,
|
|
179
|
-
willCompilerDirOrFile: config.willCompilerDirOrFile,
|
|
180
|
-
sourceMaps: config.sourceMaps,
|
|
181
|
-
compiler,
|
|
182
|
-
projectData: {
|
|
183
|
-
appDirectory: config.appDirectory
|
|
184
|
-
},
|
|
185
|
-
tsconfigPath: config.tsconfigPath,
|
|
186
|
-
babelConfig
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (code === 0) {
|
|
190
|
-
generatorRealFiles(virtualDists); // 执行成功log使用 console.info
|
|
191
|
-
|
|
192
|
-
console.info('[Babel Compiler]: Successfully');
|
|
193
|
-
} else if (messageDetails && messageDetails.length > 0) {
|
|
194
|
-
console.error(message);
|
|
195
|
-
|
|
196
|
-
for (const detail of messageDetails || []) {
|
|
197
|
-
console.error(detail.content);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (code === 0 && config.copyDirs) {
|
|
202
|
-
const copyList = config.copyDirs.split(',');
|
|
203
|
-
|
|
204
|
-
for (const copyDir of copyList) {
|
|
205
|
-
_utils.fs.ensureDirSync(copyDir);
|
|
206
|
-
|
|
207
|
-
_utils.fs.copySync(config.distDir, copyDir);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
(async () => {
|
|
213
|
-
let options;
|
|
214
|
-
|
|
215
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
216
|
-
({
|
|
217
|
-
options
|
|
218
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const {
|
|
222
|
-
resolved
|
|
223
|
-
} = await core.cli.init([], options);
|
|
224
|
-
|
|
225
|
-
(async () => {
|
|
226
|
-
try {
|
|
227
|
-
await taskMain({
|
|
228
|
-
modernConfig: resolved
|
|
229
|
-
});
|
|
230
|
-
} catch (e) {
|
|
231
|
-
console.error(e);
|
|
232
|
-
}
|
|
233
|
-
})();
|
|
234
|
-
})();
|
|
@@ -1,184 +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 cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
|
|
12
|
-
|
|
13
|
-
const core = _utils.Import.lazy('@modern-js/core', require);
|
|
14
|
-
|
|
15
|
-
const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
|
|
16
|
-
|
|
17
|
-
const hooks = _utils.Import.lazy('../hooks', require);
|
|
18
|
-
|
|
19
|
-
const STYLE_DIRS = 'styles';
|
|
20
|
-
const SRC_STYLE_DIRS = 'src';
|
|
21
|
-
|
|
22
|
-
const checkStylesDirExist = option => {
|
|
23
|
-
const {
|
|
24
|
-
appDirectory
|
|
25
|
-
} = option;
|
|
26
|
-
return _utils.fs.existsSync(path.join(appDirectory, STYLE_DIRS));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const generatorFileOrLogError = (result, successMessage = '') => {
|
|
30
|
-
if (result.code === 0 && result.dists.length > 0) {
|
|
31
|
-
for (const file of result.dists) {
|
|
32
|
-
_utils.fs.ensureFileSync(file.filename);
|
|
33
|
-
|
|
34
|
-
_utils.fs.writeFileSync(file.filename, file.content);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (successMessage) {
|
|
38
|
-
console.info(successMessage);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
for (const file of result.errors) {
|
|
42
|
-
console.error(file.error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const getPostcssOption = (appDirectory, modernConfig) => {
|
|
48
|
-
var _postcssOption$postcs;
|
|
49
|
-
|
|
50
|
-
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
51
|
-
return {
|
|
52
|
-
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
53
|
-
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
54
|
-
options: {}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const copyOriginStyleFiles = ({
|
|
59
|
-
targetDir,
|
|
60
|
-
outputDir
|
|
61
|
-
}) => {
|
|
62
|
-
const styleFiles = _utils.glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
|
|
63
|
-
|
|
64
|
-
if (styleFiles.length > 0) {
|
|
65
|
-
_utils.fs.ensureDirSync(outputDir);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const styleFile of styleFiles) {
|
|
69
|
-
const file = path.relative(targetDir, styleFile);
|
|
70
|
-
|
|
71
|
-
_utils.fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
|
|
72
|
-
|
|
73
|
-
_utils.fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const taskMain = async ({
|
|
78
|
-
modernConfig,
|
|
79
|
-
appContext
|
|
80
|
-
}) => {
|
|
81
|
-
const {
|
|
82
|
-
assetsPath = 'styles',
|
|
83
|
-
path: outputPath = 'dist',
|
|
84
|
-
jsPath = 'js'
|
|
85
|
-
} = modernConfig.output;
|
|
86
|
-
const {
|
|
87
|
-
appDirectory
|
|
88
|
-
} = appContext;
|
|
89
|
-
const lessOption = await core.mountHook().moduleLessConfig({
|
|
90
|
-
modernConfig
|
|
91
|
-
}, {
|
|
92
|
-
onLast: async _ => undefined
|
|
93
|
-
});
|
|
94
|
-
const sassOption = await core.mountHook().moduleSassConfig({
|
|
95
|
-
modernConfig
|
|
96
|
-
}, {
|
|
97
|
-
onLast: async _ => undefined
|
|
98
|
-
});
|
|
99
|
-
const tailwindPlugin = await core.mountHook().moduleTailwindConfig({
|
|
100
|
-
modernConfig
|
|
101
|
-
}, {
|
|
102
|
-
onLast: async _ => undefined
|
|
103
|
-
});
|
|
104
|
-
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
105
|
-
|
|
106
|
-
if (tailwindPlugin) {
|
|
107
|
-
var _postcssOption$plugin;
|
|
108
|
-
|
|
109
|
-
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
importStyle
|
|
114
|
-
} = modernConfig.output;
|
|
115
|
-
const existStylesDir = checkStylesDirExist({
|
|
116
|
-
appDirectory
|
|
117
|
-
}); // 编译 styles 目录样式
|
|
118
|
-
|
|
119
|
-
if (existStylesDir) {
|
|
120
|
-
const styleResult = await compiler.styleCompiler({
|
|
121
|
-
projectDir: appDirectory,
|
|
122
|
-
stylesDir: path.resolve(appDirectory, STYLE_DIRS),
|
|
123
|
-
outDir: path.join(appDirectory, outputPath, assetsPath),
|
|
124
|
-
enableVirtualDist: true,
|
|
125
|
-
compilerOption: {
|
|
126
|
-
less: lessOption,
|
|
127
|
-
sass: sassOption,
|
|
128
|
-
postcss: postcssOption
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
generatorFileOrLogError(styleResult, `[Style Compiler] Successfully for 'styles' dir`);
|
|
132
|
-
} // 编译 src 内的样式代码
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const srcDir = path.resolve(appDirectory, SRC_STYLE_DIRS);
|
|
136
|
-
const outputDirToSrc = path.join(appDirectory, outputPath, jsPath, assetsPath);
|
|
137
|
-
|
|
138
|
-
if (importStyle === 'compiled-code') {
|
|
139
|
-
const srcStyleResult = await compiler.styleCompiler({
|
|
140
|
-
projectDir: appDirectory,
|
|
141
|
-
stylesDir: srcDir,
|
|
142
|
-
outDir: outputDirToSrc,
|
|
143
|
-
enableVirtualDist: true,
|
|
144
|
-
compilerOption: {
|
|
145
|
-
less: lessOption,
|
|
146
|
-
sass: sassOption,
|
|
147
|
-
postcss: postcssOption
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
generatorFileOrLogError(srcStyleResult, `[Style Compiler] Successfully for 'src' dir`);
|
|
151
|
-
} else {
|
|
152
|
-
copyOriginStyleFiles({
|
|
153
|
-
targetDir: srcDir,
|
|
154
|
-
outputDir: outputDirToSrc
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
(async () => {
|
|
160
|
-
let options;
|
|
161
|
-
|
|
162
|
-
if (process.env.CORE_INIT_OPTION_FILE) {
|
|
163
|
-
({
|
|
164
|
-
options
|
|
165
|
-
} = require(process.env.CORE_INIT_OPTION_FILE));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
hooks.buildLifeCycle();
|
|
169
|
-
const {
|
|
170
|
-
resolved: modernConfig,
|
|
171
|
-
appContext
|
|
172
|
-
} = await core.cli.init([], options);
|
|
173
|
-
|
|
174
|
-
(async () => {
|
|
175
|
-
try {
|
|
176
|
-
await taskMain({
|
|
177
|
-
modernConfig,
|
|
178
|
-
appContext
|
|
179
|
-
});
|
|
180
|
-
} catch (e) {
|
|
181
|
-
console.error(e.toString());
|
|
182
|
-
}
|
|
183
|
-
})();
|
|
184
|
-
})();
|
|
@@ -1,174 +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
|
-
|
|
165
|
-
(async () => {
|
|
166
|
-
try {
|
|
167
|
-
await taskMain({
|
|
168
|
-
modernConfig: resolved
|
|
169
|
-
});
|
|
170
|
-
} catch (e) {
|
|
171
|
-
console.error(e);
|
|
172
|
-
}
|
|
173
|
-
})();
|
|
174
|
-
})();
|