@tarojs/service 3.5.0-canary.0 → 3.5.0-theta.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/dist/Config.js +8 -8
- package/dist/Kernel.d.ts +4 -4
- package/dist/Kernel.js +46 -44
- package/dist/Plugin.d.ts +1 -1
- package/dist/Plugin.js +1 -1
- package/dist/platform-plugin-base.d.ts +1 -0
- package/dist/platform-plugin-base.js +35 -15
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +11 -5
- package/index.js +1 -0
- package/package.json +18 -19
- package/src/Config.ts +16 -11
- package/src/Kernel.ts +61 -50
- package/src/Plugin.ts +1 -1
- package/src/platform-plugin-base.ts +40 -14
- package/src/utils/index.ts +10 -7
- package/src/utils/types.ts +2 -2
- package/types/index.d.ts +1 -1
package/dist/Config.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs-extra");
|
|
5
|
-
const lodash_1 = require("lodash");
|
|
6
3
|
const helper_1 = require("@tarojs/helper");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const merge = require("webpack-merge");
|
|
7
7
|
const constants_1 = require("./utils/constants");
|
|
8
8
|
class Config {
|
|
9
9
|
constructor(opts) {
|
|
@@ -11,19 +11,19 @@ class Config {
|
|
|
11
11
|
this.init();
|
|
12
12
|
}
|
|
13
13
|
init() {
|
|
14
|
-
this.configPath = helper_1.resolveScriptPath(path.join(this.appPath, constants_1.CONFIG_DIR_NAME, constants_1.DEFAULT_CONFIG_FILE));
|
|
14
|
+
this.configPath = (0, helper_1.resolveScriptPath)(path.join(this.appPath, constants_1.CONFIG_DIR_NAME, constants_1.DEFAULT_CONFIG_FILE));
|
|
15
15
|
if (!fs.existsSync(this.configPath)) {
|
|
16
16
|
this.initialConfig = {};
|
|
17
17
|
this.isInitSuccess = false;
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
helper_1.
|
|
20
|
+
(0, helper_1.createSwcRegister)({
|
|
21
21
|
only: [
|
|
22
22
|
filePath => filePath.indexOf(path.join(this.appPath, constants_1.CONFIG_DIR_NAME)) >= 0
|
|
23
23
|
]
|
|
24
24
|
});
|
|
25
25
|
try {
|
|
26
|
-
this.initialConfig = helper_1.getModuleDefaultExport(require(this.configPath))(
|
|
26
|
+
this.initialConfig = (0, helper_1.getModuleDefaultExport)(require(this.configPath))(merge);
|
|
27
27
|
this.isInitSuccess = true;
|
|
28
28
|
}
|
|
29
29
|
catch (err) {
|
|
@@ -39,11 +39,11 @@ class Config {
|
|
|
39
39
|
const outputDirName = initialConfig.outputRoot || helper_1.OUTPUT_DIR;
|
|
40
40
|
const sourceDir = path.join(this.appPath, sourceDirName);
|
|
41
41
|
const entryName = helper_1.ENTRY;
|
|
42
|
-
const entryFilePath = helper_1.resolveScriptPath(path.join(sourceDir, entryName));
|
|
42
|
+
const entryFilePath = (0, helper_1.resolveScriptPath)(path.join(sourceDir, entryName));
|
|
43
43
|
const entry = {
|
|
44
44
|
[entryName]: [entryFilePath]
|
|
45
45
|
};
|
|
46
|
-
return Object.assign({ entry, alias: initialConfig.alias || {}, copy: initialConfig.copy, sourceRoot: sourceDirName, outputRoot: outputDirName, platform, framework: initialConfig.framework, baseLevel: initialConfig.baseLevel, csso: initialConfig.csso, sass: initialConfig.sass, uglify: initialConfig.uglify, plugins: initialConfig.plugins, projectName: initialConfig.projectName, env: initialConfig.env, defineConstants: initialConfig.defineConstants, designWidth: initialConfig.designWidth, deviceRatio: initialConfig.deviceRatio, projectConfigName: initialConfig.projectConfigName, terser: initialConfig.terser }, initialConfig[useConfigName]);
|
|
46
|
+
return Object.assign({ entry, alias: initialConfig.alias || {}, copy: initialConfig.copy, sourceRoot: sourceDirName, outputRoot: outputDirName, platform, framework: initialConfig.framework, compiler: initialConfig.compiler, cache: initialConfig.cache, logger: initialConfig.logger, baseLevel: initialConfig.baseLevel, csso: initialConfig.csso, sass: initialConfig.sass, uglify: initialConfig.uglify, plugins: initialConfig.plugins, projectName: initialConfig.projectName, env: initialConfig.env, defineConstants: initialConfig.defineConstants, designWidth: initialConfig.designWidth, deviceRatio: initialConfig.deviceRatio, projectConfigName: initialConfig.projectConfigName, jsMinimizer: initialConfig.jsMinimizer, cssMinimizer: initialConfig.cssMinimizer, terser: initialConfig.terser, esbuild: initialConfig.esbuild }, initialConfig[useConfigName]);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.default = Config;
|
package/dist/Kernel.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
2
|
import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile';
|
|
4
|
-
import {
|
|
5
|
-
import Plugin from './Plugin';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
6
4
|
import Config from './Config';
|
|
5
|
+
import Plugin from './Plugin';
|
|
6
|
+
import { ICommand, IHook, IPaths, IPlatform, IPlugin, IPluginsObject, IPreset } from './utils/types';
|
|
7
7
|
interface IKernelOptions {
|
|
8
8
|
appPath: string;
|
|
9
9
|
presets?: PluginItem[];
|
|
@@ -28,7 +28,6 @@ export default class Kernel extends EventEmitter {
|
|
|
28
28
|
runOpts: any;
|
|
29
29
|
debugger: any;
|
|
30
30
|
constructor(options: IKernelOptions);
|
|
31
|
-
init(): Promise<void>;
|
|
32
31
|
initConfig(): void;
|
|
33
32
|
initPaths(): void;
|
|
34
33
|
initHelper(): void;
|
|
@@ -51,6 +50,7 @@ export default class Kernel extends EventEmitter {
|
|
|
51
50
|
}): Promise<any>;
|
|
52
51
|
runWithPlatform(platform: any): any;
|
|
53
52
|
setRunOpts(opts: any): void;
|
|
53
|
+
runHelp(name: string): void;
|
|
54
54
|
run(args: string | {
|
|
55
55
|
name: string;
|
|
56
56
|
opts?: any;
|
package/dist/Kernel.js
CHANGED
|
@@ -9,21 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const helper_1 = require("@tarojs/helper");
|
|
13
|
+
const helper = require("@tarojs/helper");
|
|
13
14
|
const events_1 = require("events");
|
|
14
15
|
const lodash_1 = require("lodash");
|
|
16
|
+
const path = require("path");
|
|
15
17
|
const tapable_1 = require("tapable");
|
|
16
|
-
const helper_1 = require("@tarojs/helper");
|
|
17
|
-
const helper = require("@tarojs/helper");
|
|
18
|
-
const joi = require("@hapi/joi");
|
|
19
|
-
const constants_1 = require("./utils/constants");
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
const Plugin_1 = require("./Plugin");
|
|
22
18
|
const Config_1 = require("./Config");
|
|
19
|
+
const Plugin_1 = require("./Plugin");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const constants_1 = require("./utils/constants");
|
|
23
22
|
class Kernel extends events_1.EventEmitter {
|
|
24
23
|
constructor(options) {
|
|
25
24
|
super();
|
|
26
|
-
this.debugger = helper_1.createDebug('Taro:Kernel');
|
|
25
|
+
this.debugger = process.env.DEBUG === 'Taro:Kernel' ? (0, helper_1.createDebug)('Taro:Kernel') : function () { };
|
|
27
26
|
this.appPath = options.appPath || process.cwd();
|
|
28
27
|
this.optsPresets = options.presets;
|
|
29
28
|
this.optsPlugins = options.plugins;
|
|
@@ -32,15 +31,8 @@ class Kernel extends events_1.EventEmitter {
|
|
|
32
31
|
this.commands = new Map();
|
|
33
32
|
this.platforms = new Map();
|
|
34
33
|
this.initHelper();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
this.debugger('init');
|
|
39
|
-
this.initConfig();
|
|
40
|
-
this.initPaths();
|
|
41
|
-
this.initPresetsAndPlugins();
|
|
42
|
-
yield this.applyPlugins('onReady');
|
|
43
|
-
});
|
|
34
|
+
this.initConfig();
|
|
35
|
+
this.initPaths();
|
|
44
36
|
}
|
|
45
37
|
initConfig() {
|
|
46
38
|
this.config = new Config_1.default({
|
|
@@ -52,13 +44,13 @@ class Kernel extends events_1.EventEmitter {
|
|
|
52
44
|
initPaths() {
|
|
53
45
|
this.paths = {
|
|
54
46
|
appPath: this.appPath,
|
|
55
|
-
nodeModulesPath: helper_1.recursiveFindNodeModules(path.join(this.appPath, helper_1.NODE_MODULES))
|
|
47
|
+
nodeModulesPath: (0, helper_1.recursiveFindNodeModules)(path.join(this.appPath, helper_1.NODE_MODULES))
|
|
56
48
|
};
|
|
57
49
|
if (this.config.isInitSuccess) {
|
|
58
50
|
Object.assign(this.paths, {
|
|
59
51
|
configPath: this.config.configPath,
|
|
60
52
|
sourcePath: path.join(this.appPath, this.initialConfig.sourceRoot),
|
|
61
|
-
outputPath: path.
|
|
53
|
+
outputPath: path.join(this.appPath, this.initialConfig.outputRoot)
|
|
62
54
|
});
|
|
63
55
|
}
|
|
64
56
|
this.debugger(`initPaths:${JSON.stringify(this.paths, null, 2)}`);
|
|
@@ -69,11 +61,11 @@ class Kernel extends events_1.EventEmitter {
|
|
|
69
61
|
}
|
|
70
62
|
initPresetsAndPlugins() {
|
|
71
63
|
const initialConfig = this.initialConfig;
|
|
72
|
-
const allConfigPresets = utils_1.mergePlugins(this.optsPresets || [], initialConfig.presets || [])();
|
|
73
|
-
const allConfigPlugins = utils_1.mergePlugins(this.optsPlugins || [], initialConfig.plugins || [])();
|
|
64
|
+
const allConfigPresets = (0, utils_1.mergePlugins)(this.optsPresets || [], initialConfig.presets || [])();
|
|
65
|
+
const allConfigPlugins = (0, utils_1.mergePlugins)(this.optsPlugins || [], initialConfig.plugins || [])();
|
|
74
66
|
this.debugger('initPresetsAndPlugins', allConfigPresets, allConfigPlugins);
|
|
75
67
|
process.env.NODE_ENV !== 'test' &&
|
|
76
|
-
helper_1.
|
|
68
|
+
(0, helper_1.createSwcRegister)({
|
|
77
69
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
78
70
|
});
|
|
79
71
|
this.plugins = new Map();
|
|
@@ -82,14 +74,14 @@ class Kernel extends events_1.EventEmitter {
|
|
|
82
74
|
this.resolvePlugins(allConfigPlugins);
|
|
83
75
|
}
|
|
84
76
|
resolvePresets(presets) {
|
|
85
|
-
const allPresets = utils_1.resolvePresetsOrPlugins(this.appPath, presets, constants_1.PluginType.Preset);
|
|
77
|
+
const allPresets = (0, utils_1.resolvePresetsOrPlugins)(this.appPath, presets, constants_1.PluginType.Preset);
|
|
86
78
|
while (allPresets.length) {
|
|
87
79
|
this.initPreset(allPresets.shift());
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
resolvePlugins(plugins) {
|
|
91
|
-
plugins = lodash_1.merge(this.extraPlugins, plugins);
|
|
92
|
-
const allPlugins = utils_1.resolvePresetsOrPlugins(this.appPath, plugins, constants_1.PluginType.Plugin);
|
|
83
|
+
plugins = (0, lodash_1.merge)(this.extraPlugins, plugins);
|
|
84
|
+
const allPlugins = (0, utils_1.resolvePresetsOrPlugins)(this.appPath, plugins, constants_1.PluginType.Plugin);
|
|
93
85
|
while (allPlugins.length) {
|
|
94
86
|
this.initPlugin(allPlugins.shift());
|
|
95
87
|
}
|
|
@@ -102,13 +94,13 @@ class Kernel extends events_1.EventEmitter {
|
|
|
102
94
|
const { presets, plugins } = apply()(pluginCtx, opts) || {};
|
|
103
95
|
this.registerPlugin(preset);
|
|
104
96
|
if (Array.isArray(presets)) {
|
|
105
|
-
const _presets = utils_1.resolvePresetsOrPlugins(this.appPath, utils_1.convertPluginsToObject(presets)(), constants_1.PluginType.Preset);
|
|
97
|
+
const _presets = (0, utils_1.resolvePresetsOrPlugins)(this.appPath, (0, utils_1.convertPluginsToObject)(presets)(), constants_1.PluginType.Preset);
|
|
106
98
|
while (_presets.length) {
|
|
107
99
|
this.initPreset(_presets.shift());
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
102
|
if (Array.isArray(plugins)) {
|
|
111
|
-
this.extraPlugins = lodash_1.merge(this.extraPlugins, utils_1.convertPluginsToObject(plugins)());
|
|
103
|
+
this.extraPlugins = (0, lodash_1.merge)(this.extraPlugins, (0, utils_1.convertPluginsToObject)(plugins)());
|
|
112
104
|
}
|
|
113
105
|
}
|
|
114
106
|
initPlugin(plugin) {
|
|
@@ -123,6 +115,8 @@ class Kernel extends events_1.EventEmitter {
|
|
|
123
115
|
if (typeof pluginCtx.optsSchema !== 'function') {
|
|
124
116
|
return;
|
|
125
117
|
}
|
|
118
|
+
this.debugger('checkPluginOpts', pluginCtx);
|
|
119
|
+
const joi = require('joi');
|
|
126
120
|
const schema = pluginCtx.optsSchema(joi);
|
|
127
121
|
if (!joi.isSchema(schema)) {
|
|
128
122
|
throw new Error(`插件${pluginCtx.id}中设置参数检查 schema 有误,请检查!`);
|
|
@@ -134,6 +128,7 @@ class Kernel extends events_1.EventEmitter {
|
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
130
|
registerPlugin(plugin) {
|
|
131
|
+
this.debugger('registerPlugin', plugin);
|
|
137
132
|
if (this.plugins.has(plugin.id)) {
|
|
138
133
|
throw new Error(`插件 ${plugin.id} 已被注册`);
|
|
139
134
|
}
|
|
@@ -198,6 +193,9 @@ class Kernel extends events_1.EventEmitter {
|
|
|
198
193
|
throw new Error('调用失败,未传入正确的名称!');
|
|
199
194
|
}
|
|
200
195
|
const hooks = this.hooks.get(name) || [];
|
|
196
|
+
if (!hooks.length) {
|
|
197
|
+
return yield initialVal;
|
|
198
|
+
}
|
|
201
199
|
const waterfall = new tapable_1.AsyncSeriesWaterfallHook(['arg']);
|
|
202
200
|
if (hooks.length) {
|
|
203
201
|
const resArr = [];
|
|
@@ -233,6 +231,17 @@ class Kernel extends events_1.EventEmitter {
|
|
|
233
231
|
setRunOpts(opts) {
|
|
234
232
|
this.runOpts = opts;
|
|
235
233
|
}
|
|
234
|
+
runHelp(name) {
|
|
235
|
+
const command = this.commands.get(name);
|
|
236
|
+
const defaultOptionsMap = new Map();
|
|
237
|
+
defaultOptionsMap.set('-h, --help', 'output usage information');
|
|
238
|
+
let customOptionsMap = new Map();
|
|
239
|
+
if (command === null || command === void 0 ? void 0 : command.optionsMap) {
|
|
240
|
+
customOptionsMap = new Map(Object.entries(command === null || command === void 0 ? void 0 : command.optionsMap));
|
|
241
|
+
}
|
|
242
|
+
const optionsMap = new Map([...customOptionsMap, ...defaultOptionsMap]);
|
|
243
|
+
(0, utils_1.printHelpLog)(name, optionsMap, (command === null || command === void 0 ? void 0 : command.synopsisList) ? new Set(command === null || command === void 0 ? void 0 : command.synopsisList) : new Set());
|
|
244
|
+
}
|
|
236
245
|
run(args) {
|
|
237
246
|
var _a;
|
|
238
247
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -250,33 +259,26 @@ class Kernel extends events_1.EventEmitter {
|
|
|
250
259
|
this.debugger('command:runOpts');
|
|
251
260
|
this.debugger(`command:runOpts:${JSON.stringify(opts, null, 2)}`);
|
|
252
261
|
this.setRunOpts(opts);
|
|
253
|
-
|
|
262
|
+
this.debugger('initPresetsAndPlugins');
|
|
263
|
+
this.initPresetsAndPlugins();
|
|
264
|
+
yield this.applyPlugins('onReady');
|
|
254
265
|
this.debugger('command:onStart');
|
|
255
266
|
yield this.applyPlugins('onStart');
|
|
256
267
|
if (!this.commands.has(name)) {
|
|
257
268
|
throw new Error(`${name} 命令不存在`);
|
|
258
269
|
}
|
|
259
270
|
if (opts === null || opts === void 0 ? void 0 : opts.isHelp) {
|
|
260
|
-
|
|
261
|
-
const defaultOptionsMap = new Map();
|
|
262
|
-
defaultOptionsMap.set('-h, --help', 'output usage information');
|
|
263
|
-
let customOptionsMap = new Map();
|
|
264
|
-
if (command === null || command === void 0 ? void 0 : command.optionsMap) {
|
|
265
|
-
customOptionsMap = new Map(Object.entries(command === null || command === void 0 ? void 0 : command.optionsMap));
|
|
266
|
-
}
|
|
267
|
-
const optionsMap = new Map([...customOptionsMap, ...defaultOptionsMap]);
|
|
268
|
-
utils_1.printHelpLog(name, optionsMap, (command === null || command === void 0 ? void 0 : command.synopsisList) ? new Set(command === null || command === void 0 ? void 0 : command.synopsisList) : new Set());
|
|
269
|
-
return;
|
|
271
|
+
return this.runHelp(name);
|
|
270
272
|
}
|
|
271
273
|
if ((_a = opts === null || opts === void 0 ? void 0 : opts.options) === null || _a === void 0 ? void 0 : _a.platform) {
|
|
272
274
|
opts.config = this.runWithPlatform(opts.options.platform);
|
|
275
|
+
yield this.applyPlugins({
|
|
276
|
+
name: 'modifyRunnerOpts',
|
|
277
|
+
opts: {
|
|
278
|
+
opts: opts === null || opts === void 0 ? void 0 : opts.config
|
|
279
|
+
}
|
|
280
|
+
});
|
|
273
281
|
}
|
|
274
|
-
yield this.applyPlugins({
|
|
275
|
-
name: 'modifyRunnerOpts',
|
|
276
|
-
opts: {
|
|
277
|
-
opts: opts === null || opts === void 0 ? void 0 : opts.config
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
282
|
yield this.applyPlugins({
|
|
281
283
|
name,
|
|
282
284
|
opts
|
package/dist/Plugin.d.ts
CHANGED
package/dist/Plugin.js
CHANGED
|
@@ -29,7 +29,7 @@ class Plugin {
|
|
|
29
29
|
if (this.ctx.platforms.has(platform.name)) {
|
|
30
30
|
throw new Error(`适配平台 ${platform.name} 已存在`);
|
|
31
31
|
}
|
|
32
|
-
helper_1.addPlatforms(platform.name);
|
|
32
|
+
(0, helper_1.addPlatforms)(platform.name);
|
|
33
33
|
this.ctx.platforms.set(platform.name, platform);
|
|
34
34
|
this.register(platform);
|
|
35
35
|
}
|
|
@@ -40,6 +40,8 @@ class TaroPlatformBase {
|
|
|
40
40
|
this.ctx = ctx;
|
|
41
41
|
this.helper = ctx.helper;
|
|
42
42
|
this.config = config;
|
|
43
|
+
const _compiler = config.compiler;
|
|
44
|
+
this.compiler = typeof _compiler === 'object' ? _compiler.type : _compiler;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* 1. 清空 dist 文件夹
|
|
@@ -54,36 +56,46 @@ class TaroPlatformBase {
|
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
setupImpl() {
|
|
59
|
+
var _a;
|
|
57
60
|
const { needClearOutput } = this.config;
|
|
58
61
|
if (typeof needClearOutput === 'undefined' || !!needClearOutput) {
|
|
59
62
|
this.emptyOutputDir();
|
|
60
63
|
}
|
|
61
64
|
this.printDevelopmentTip(this.platform);
|
|
62
|
-
const { printLog, processTypeEnum } = this.ctx.helper;
|
|
63
|
-
printLog("start" /* START */, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`);
|
|
64
65
|
if (this.projectConfigJson) {
|
|
65
66
|
this.generateProjectConfig(this.projectConfigJson);
|
|
66
67
|
}
|
|
68
|
+
if (((_a = this.ctx.initialConfig.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
|
|
69
|
+
const { printLog, processTypeEnum } = this.ctx.helper;
|
|
70
|
+
printLog("start" /* START */, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`);
|
|
71
|
+
}
|
|
67
72
|
}
|
|
68
73
|
emptyOutputDir() {
|
|
69
74
|
const { outputPath } = this.ctx.paths;
|
|
70
75
|
this.helper.emptyDirectory(outputPath);
|
|
71
76
|
}
|
|
72
77
|
printDevelopmentTip(platform) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
78
|
+
var _a;
|
|
79
|
+
const tips = [];
|
|
80
|
+
const config = this.config;
|
|
81
|
+
const { chalk } = this.helper;
|
|
82
|
+
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
|
83
|
+
const { isWindows } = this.helper;
|
|
84
|
+
const exampleCommand = isWindows
|
|
85
|
+
? `$ set NODE_ENV=production && taro build --type ${platform} --watch`
|
|
86
|
+
: `$ NODE_ENV=production taro build --type ${platform} --watch`;
|
|
87
|
+
tips.push(chalk.yellowBright(`预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
|
|
88
|
+
Example:
|
|
89
|
+
${exampleCommand}`));
|
|
79
90
|
}
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
if (this.compiler === 'webpack5' && !((_a = config.cache) === null || _a === void 0 ? void 0 : _a.enable)) {
|
|
92
|
+
tips.push(chalk.yellowBright('建议开启持久化缓存功能,能有效提升二次编译速度,详情请参考: https://docs.taro.zone/docs/config-detail#cache。'));
|
|
93
|
+
}
|
|
94
|
+
if (tips.length) {
|
|
95
|
+
console.log(chalk.yellowBright('Tips:'));
|
|
96
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`));
|
|
97
|
+
console.log('\n');
|
|
82
98
|
}
|
|
83
|
-
console.log(chalk.yellowBright(`Tips: 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
|
|
84
|
-
Example:
|
|
85
|
-
${exampleCommand}
|
|
86
|
-
`));
|
|
87
99
|
}
|
|
88
100
|
/**
|
|
89
101
|
* 返回当前项目内的 @tarojs/mini-runner 包
|
|
@@ -92,7 +104,15 @@ ${exampleCommand}
|
|
|
92
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
105
|
const { appPath } = this.ctx.paths;
|
|
94
106
|
const { npm } = this.helper;
|
|
95
|
-
|
|
107
|
+
let runnerPkg;
|
|
108
|
+
switch (this.compiler) {
|
|
109
|
+
case 'webpack5':
|
|
110
|
+
runnerPkg = '@tarojs/webpack5-runner';
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
runnerPkg = '@tarojs/mini-runner';
|
|
114
|
+
}
|
|
115
|
+
const runner = yield npm.getNpmPkg(runnerPkg, appPath);
|
|
96
116
|
return runner.bind(null, appPath);
|
|
97
117
|
});
|
|
98
118
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PluginItem } from '@tarojs/taro/types/compile';
|
|
1
|
+
import type { PluginItem } from '@tarojs/taro/types/compile';
|
|
2
2
|
import { PluginType } from './constants';
|
|
3
|
-
import {
|
|
3
|
+
import { IPlugin, IPluginsObject } from './types';
|
|
4
4
|
export declare const isNpmPkg: (name: string) => boolean;
|
|
5
5
|
export declare function getPluginPath(pluginPath: string): string;
|
|
6
6
|
export declare function convertPluginsToObject(items: PluginItem[]): () => IPluginsObject;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printHelpLog = exports.resolvePresetsOrPlugins = exports.mergePlugins = exports.convertPluginsToObject = exports.getPluginPath = exports.isNpmPkg = void 0;
|
|
4
|
-
const
|
|
4
|
+
const helper_1 = require("@tarojs/helper");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
const resolve = require("resolve");
|
|
7
|
-
const helper_1 = require("@tarojs/helper");
|
|
8
8
|
const isNpmPkg = name => !(/^(\.|\/)/.test(name));
|
|
9
9
|
exports.isNpmPkg = isNpmPkg;
|
|
10
10
|
function getPluginPath(pluginPath) {
|
|
11
|
-
if (exports.isNpmPkg(pluginPath) || path.isAbsolute(pluginPath))
|
|
11
|
+
if ((0, exports.isNpmPkg)(pluginPath) || path.isAbsolute(pluginPath))
|
|
12
12
|
return pluginPath;
|
|
13
13
|
throw new Error('plugin 和 preset 配置必须为绝对路径或者包名');
|
|
14
14
|
}
|
|
@@ -36,7 +36,7 @@ function mergePlugins(dist, src) {
|
|
|
36
36
|
return () => {
|
|
37
37
|
const srcObj = convertPluginsToObject(src)();
|
|
38
38
|
const distObj = convertPluginsToObject(dist)();
|
|
39
|
-
return lodash_1.merge(distObj, srcObj);
|
|
39
|
+
return (0, lodash_1.merge)(distObj, srcObj);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
exports.mergePlugins = mergePlugins;
|
|
@@ -67,7 +67,13 @@ function resolvePresetsOrPlugins(root, args, type) {
|
|
|
67
67
|
type,
|
|
68
68
|
opts: args[item] || {},
|
|
69
69
|
apply() {
|
|
70
|
-
|
|
70
|
+
try {
|
|
71
|
+
return (0, helper_1.getModuleDefaultExport)(require(fPath));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error(error);
|
|
75
|
+
throw new Error(`插件依赖 "${item}" 加载失败,请检查插件配置`);
|
|
76
|
+
}
|
|
71
77
|
}
|
|
72
78
|
};
|
|
73
79
|
});
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/service",
|
|
3
|
-
"version": "3.5.0-
|
|
3
|
+
"version": "3.5.0-theta.1",
|
|
4
4
|
"description": "Taro Service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "run-s clean prod",
|
|
9
|
-
"dev": "tsc -w",
|
|
10
|
-
"prod": "tsc",
|
|
11
|
-
"clean": "rimraf dist",
|
|
12
|
-
"prepack": "npm run build",
|
|
13
|
-
"test": "jest",
|
|
14
|
-
"test:dev": "jest --watch"
|
|
15
|
-
},
|
|
16
7
|
"repository": {
|
|
17
8
|
"type": "git",
|
|
18
9
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
@@ -33,14 +24,22 @@
|
|
|
33
24
|
},
|
|
34
25
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
35
26
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@tarojs/
|
|
38
|
-
"@tarojs/
|
|
39
|
-
"
|
|
40
|
-
"
|
|
27
|
+
"@tarojs/helper": "3.5.0-theta.1",
|
|
28
|
+
"@tarojs/shared": "3.5.0-theta.1",
|
|
29
|
+
"@tarojs/taro": "3.5.0-theta.1",
|
|
30
|
+
"fs-extra": "^8.1.0",
|
|
31
|
+
"joi": "^17.6.0",
|
|
41
32
|
"lodash": "^4.17.21",
|
|
42
|
-
"resolve": "^1.
|
|
43
|
-
"tapable": "^1.1.3"
|
|
33
|
+
"resolve": "^1.22.0",
|
|
34
|
+
"tapable": "^1.1.3",
|
|
35
|
+
"webpack-merge": "^4.2.2"
|
|
44
36
|
},
|
|
45
|
-
"
|
|
46
|
-
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "run-s clean prod",
|
|
39
|
+
"dev": "tsc -w",
|
|
40
|
+
"prod": "tsc",
|
|
41
|
+
"clean": "rimraf dist",
|
|
42
|
+
"test": "jest",
|
|
43
|
+
"test:dev": "jest --watch"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/Config.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import * as path from 'path'
|
|
2
|
-
import * as fs from 'fs-extra'
|
|
3
|
-
|
|
4
|
-
import { merge } from 'lodash'
|
|
5
|
-
import { IProjectConfig } from '@tarojs/taro/types/compile'
|
|
6
1
|
import {
|
|
7
|
-
|
|
8
|
-
OUTPUT_DIR,
|
|
2
|
+
createSwcRegister,
|
|
9
3
|
ENTRY,
|
|
4
|
+
getModuleDefaultExport,
|
|
5
|
+
OUTPUT_DIR,
|
|
10
6
|
resolveScriptPath,
|
|
11
|
-
|
|
12
|
-
getModuleDefaultExport
|
|
7
|
+
SOURCE_DIR
|
|
13
8
|
} from '@tarojs/helper'
|
|
9
|
+
import { IProjectConfig } from '@tarojs/taro/types/compile'
|
|
10
|
+
import * as fs from 'fs-extra'
|
|
11
|
+
import * as path from 'path'
|
|
12
|
+
import * as merge from 'webpack-merge'
|
|
14
13
|
|
|
15
14
|
import {
|
|
16
15
|
CONFIG_DIR_NAME,
|
|
@@ -18,7 +17,7 @@ import {
|
|
|
18
17
|
} from './utils/constants'
|
|
19
18
|
|
|
20
19
|
interface IConfigOptions {
|
|
21
|
-
appPath: string
|
|
20
|
+
appPath: string
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export default class Config {
|
|
@@ -37,7 +36,7 @@ export default class Config {
|
|
|
37
36
|
this.initialConfig = {}
|
|
38
37
|
this.isInitSuccess = false
|
|
39
38
|
} else {
|
|
40
|
-
|
|
39
|
+
createSwcRegister({
|
|
41
40
|
only: [
|
|
42
41
|
filePath => filePath.indexOf(path.join(this.appPath, CONFIG_DIR_NAME)) >= 0
|
|
43
42
|
]
|
|
@@ -73,6 +72,9 @@ export default class Config {
|
|
|
73
72
|
outputRoot: outputDirName,
|
|
74
73
|
platform,
|
|
75
74
|
framework: initialConfig.framework,
|
|
75
|
+
compiler: initialConfig.compiler,
|
|
76
|
+
cache: initialConfig.cache,
|
|
77
|
+
logger: initialConfig.logger,
|
|
76
78
|
baseLevel: initialConfig.baseLevel,
|
|
77
79
|
csso: initialConfig.csso,
|
|
78
80
|
sass: initialConfig.sass,
|
|
@@ -84,7 +86,10 @@ export default class Config {
|
|
|
84
86
|
designWidth: initialConfig.designWidth,
|
|
85
87
|
deviceRatio: initialConfig.deviceRatio,
|
|
86
88
|
projectConfigName: initialConfig.projectConfigName,
|
|
89
|
+
jsMinimizer: initialConfig.jsMinimizer,
|
|
90
|
+
cssMinimizer: initialConfig.cssMinimizer,
|
|
87
91
|
terser: initialConfig.terser,
|
|
92
|
+
esbuild: initialConfig.esbuild,
|
|
88
93
|
...initialConfig[useConfigName]
|
|
89
94
|
}
|
|
90
95
|
}
|
package/src/Kernel.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import * as path from 'path'
|
|
2
|
-
import { EventEmitter } from 'events'
|
|
3
|
-
import { merge } from 'lodash'
|
|
4
|
-
import { AsyncSeriesWaterfallHook } from 'tapable'
|
|
5
|
-
import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile'
|
|
6
1
|
import {
|
|
2
|
+
createDebug,
|
|
3
|
+
createSwcRegister,
|
|
7
4
|
NODE_MODULES,
|
|
8
|
-
recursiveFindNodeModules
|
|
9
|
-
createBabelRegister,
|
|
10
|
-
createDebug
|
|
5
|
+
recursiveFindNodeModules
|
|
11
6
|
} from '@tarojs/helper'
|
|
12
7
|
import * as helper from '@tarojs/helper'
|
|
13
|
-
import
|
|
8
|
+
import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile'
|
|
9
|
+
import { EventEmitter } from 'events'
|
|
10
|
+
import { merge } from 'lodash'
|
|
11
|
+
import * as path from 'path'
|
|
12
|
+
import { AsyncSeriesWaterfallHook } from 'tapable'
|
|
14
13
|
|
|
14
|
+
import Config from './Config'
|
|
15
|
+
import Plugin from './Plugin'
|
|
16
|
+
import { convertPluginsToObject, mergePlugins, printHelpLog, resolvePresetsOrPlugins } from './utils'
|
|
15
17
|
import {
|
|
16
|
-
IPreset,
|
|
17
|
-
IPluginsObject,
|
|
18
|
-
IPlugin,
|
|
19
|
-
IPaths,
|
|
20
|
-
IHook,
|
|
21
|
-
ICommand,
|
|
22
|
-
IPlatform
|
|
23
|
-
} from './utils/types'
|
|
24
|
-
import {
|
|
25
|
-
PluginType,
|
|
26
|
-
IS_MODIFY_HOOK,
|
|
27
18
|
IS_ADD_HOOK,
|
|
28
|
-
IS_EVENT_HOOK
|
|
19
|
+
IS_EVENT_HOOK,
|
|
20
|
+
IS_MODIFY_HOOK,
|
|
21
|
+
PluginType
|
|
29
22
|
} from './utils/constants'
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
import {
|
|
24
|
+
ICommand,
|
|
25
|
+
IHook,
|
|
26
|
+
IPaths,
|
|
27
|
+
IPlatform,
|
|
28
|
+
IPlugin,
|
|
29
|
+
IPluginsObject,
|
|
30
|
+
IPreset
|
|
31
|
+
} from './utils/types'
|
|
33
32
|
|
|
34
33
|
interface IKernelOptions {
|
|
35
34
|
appPath: string
|
|
@@ -58,7 +57,7 @@ export default class Kernel extends EventEmitter {
|
|
|
58
57
|
|
|
59
58
|
constructor (options: IKernelOptions) {
|
|
60
59
|
super()
|
|
61
|
-
this.debugger = createDebug('Taro:Kernel')
|
|
60
|
+
this.debugger = process.env.DEBUG === 'Taro:Kernel' ? createDebug('Taro:Kernel') : function () {}
|
|
62
61
|
this.appPath = options.appPath || process.cwd()
|
|
63
62
|
this.optsPresets = options.presets
|
|
64
63
|
this.optsPlugins = options.plugins
|
|
@@ -67,14 +66,8 @@ export default class Kernel extends EventEmitter {
|
|
|
67
66
|
this.commands = new Map()
|
|
68
67
|
this.platforms = new Map()
|
|
69
68
|
this.initHelper()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async init () {
|
|
73
|
-
this.debugger('init')
|
|
74
69
|
this.initConfig()
|
|
75
70
|
this.initPaths()
|
|
76
|
-
this.initPresetsAndPlugins()
|
|
77
|
-
await this.applyPlugins('onReady')
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
initConfig () {
|
|
@@ -94,7 +87,7 @@ export default class Kernel extends EventEmitter {
|
|
|
94
87
|
Object.assign(this.paths, {
|
|
95
88
|
configPath: this.config.configPath,
|
|
96
89
|
sourcePath: path.join(this.appPath, this.initialConfig.sourceRoot as string),
|
|
97
|
-
outputPath: path.
|
|
90
|
+
outputPath: path.join(this.appPath, this.initialConfig.outputRoot as string)
|
|
98
91
|
})
|
|
99
92
|
}
|
|
100
93
|
this.debugger(`initPaths:${JSON.stringify(this.paths, null, 2)}`)
|
|
@@ -111,7 +104,7 @@ export default class Kernel extends EventEmitter {
|
|
|
111
104
|
const allConfigPlugins = mergePlugins(this.optsPlugins || [], initialConfig.plugins || [])()
|
|
112
105
|
this.debugger('initPresetsAndPlugins', allConfigPresets, allConfigPlugins)
|
|
113
106
|
process.env.NODE_ENV !== 'test' &&
|
|
114
|
-
|
|
107
|
+
createSwcRegister({
|
|
115
108
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
116
109
|
})
|
|
117
110
|
this.plugins = new Map()
|
|
@@ -167,6 +160,8 @@ export default class Kernel extends EventEmitter {
|
|
|
167
160
|
if (typeof pluginCtx.optsSchema !== 'function') {
|
|
168
161
|
return
|
|
169
162
|
}
|
|
163
|
+
this.debugger('checkPluginOpts', pluginCtx)
|
|
164
|
+
const joi = require('joi')
|
|
170
165
|
const schema = pluginCtx.optsSchema(joi)
|
|
171
166
|
if (!joi.isSchema(schema)) {
|
|
172
167
|
throw new Error(`插件${pluginCtx.id}中设置参数检查 schema 有误,请检查!`)
|
|
@@ -179,6 +174,7 @@ export default class Kernel extends EventEmitter {
|
|
|
179
174
|
}
|
|
180
175
|
|
|
181
176
|
registerPlugin (plugin: IPlugin) {
|
|
177
|
+
this.debugger('registerPlugin', plugin)
|
|
182
178
|
if (this.plugins.has(plugin.id)) {
|
|
183
179
|
throw new Error(`插件 ${plugin.id} 已被注册`)
|
|
184
180
|
}
|
|
@@ -243,6 +239,9 @@ export default class Kernel extends EventEmitter {
|
|
|
243
239
|
throw new Error('调用失败,未传入正确的名称!')
|
|
244
240
|
}
|
|
245
241
|
const hooks = this.hooks.get(name) || []
|
|
242
|
+
if (!hooks.length) {
|
|
243
|
+
return await initialVal
|
|
244
|
+
}
|
|
246
245
|
const waterfall = new AsyncSeriesWaterfallHook(['arg'])
|
|
247
246
|
if (hooks.length) {
|
|
248
247
|
const resArr: any[] = []
|
|
@@ -280,6 +279,18 @@ export default class Kernel extends EventEmitter {
|
|
|
280
279
|
this.runOpts = opts
|
|
281
280
|
}
|
|
282
281
|
|
|
282
|
+
runHelp (name: string) {
|
|
283
|
+
const command = this.commands.get(name)
|
|
284
|
+
const defaultOptionsMap = new Map()
|
|
285
|
+
defaultOptionsMap.set('-h, --help', 'output usage information')
|
|
286
|
+
let customOptionsMap = new Map()
|
|
287
|
+
if (command?.optionsMap) {
|
|
288
|
+
customOptionsMap = new Map(Object.entries(command?.optionsMap))
|
|
289
|
+
}
|
|
290
|
+
const optionsMap = new Map([...customOptionsMap, ...defaultOptionsMap])
|
|
291
|
+
printHelpLog(name, optionsMap, command?.synopsisList ? new Set(command?.synopsisList) : new Set())
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
async run (args: string | { name: string, opts?: any }) {
|
|
284
295
|
let name
|
|
285
296
|
let opts
|
|
@@ -294,33 +305,33 @@ export default class Kernel extends EventEmitter {
|
|
|
294
305
|
this.debugger('command:runOpts')
|
|
295
306
|
this.debugger(`command:runOpts:${JSON.stringify(opts, null, 2)}`)
|
|
296
307
|
this.setRunOpts(opts)
|
|
297
|
-
|
|
308
|
+
|
|
309
|
+
this.debugger('initPresetsAndPlugins')
|
|
310
|
+
this.initPresetsAndPlugins()
|
|
311
|
+
|
|
312
|
+
await this.applyPlugins('onReady')
|
|
313
|
+
|
|
298
314
|
this.debugger('command:onStart')
|
|
299
315
|
await this.applyPlugins('onStart')
|
|
316
|
+
|
|
300
317
|
if (!this.commands.has(name)) {
|
|
301
318
|
throw new Error(`${name} 命令不存在`)
|
|
302
319
|
}
|
|
320
|
+
|
|
303
321
|
if (opts?.isHelp) {
|
|
304
|
-
|
|
305
|
-
const defaultOptionsMap = new Map()
|
|
306
|
-
defaultOptionsMap.set('-h, --help', 'output usage information')
|
|
307
|
-
let customOptionsMap = new Map()
|
|
308
|
-
if (command?.optionsMap) {
|
|
309
|
-
customOptionsMap = new Map(Object.entries(command?.optionsMap))
|
|
310
|
-
}
|
|
311
|
-
const optionsMap = new Map([...customOptionsMap, ...defaultOptionsMap])
|
|
312
|
-
printHelpLog(name, optionsMap, command?.synopsisList ? new Set(command?.synopsisList) : new Set())
|
|
313
|
-
return
|
|
322
|
+
return this.runHelp(name)
|
|
314
323
|
}
|
|
324
|
+
|
|
315
325
|
if (opts?.options?.platform) {
|
|
316
326
|
opts.config = this.runWithPlatform(opts.options.platform)
|
|
327
|
+
await this.applyPlugins({
|
|
328
|
+
name: 'modifyRunnerOpts',
|
|
329
|
+
opts: {
|
|
330
|
+
opts: opts?.config
|
|
331
|
+
}
|
|
332
|
+
})
|
|
317
333
|
}
|
|
318
|
-
|
|
319
|
-
name: 'modifyRunnerOpts',
|
|
320
|
-
opts: {
|
|
321
|
-
opts: opts?.config
|
|
322
|
-
}
|
|
323
|
-
})
|
|
334
|
+
|
|
324
335
|
await this.applyPlugins({
|
|
325
336
|
name,
|
|
326
337
|
opts
|
package/src/Plugin.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RecursiveTemplate, UnRecursiveTemplate } from '@tarojs/shared/dist/template'
|
|
2
|
+
|
|
2
3
|
import type { IPluginContext } from '../types/index'
|
|
3
4
|
|
|
4
5
|
interface IFileType {
|
|
@@ -42,6 +43,7 @@ export abstract class TaroPlatformBase {
|
|
|
42
43
|
ctx: IPluginContext
|
|
43
44
|
helper: IPluginContext['helper']
|
|
44
45
|
config: any
|
|
46
|
+
compiler: string
|
|
45
47
|
|
|
46
48
|
abstract platform: string
|
|
47
49
|
abstract globalObject: string
|
|
@@ -58,6 +60,8 @@ export abstract class TaroPlatformBase {
|
|
|
58
60
|
this.ctx = ctx
|
|
59
61
|
this.helper = ctx.helper
|
|
60
62
|
this.config = config
|
|
63
|
+
const _compiler = config.compiler
|
|
64
|
+
this.compiler = typeof _compiler === 'object' ? _compiler.type : _compiler
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
|
@@ -76,11 +80,13 @@ export abstract class TaroPlatformBase {
|
|
|
76
80
|
this.emptyOutputDir()
|
|
77
81
|
}
|
|
78
82
|
this.printDevelopmentTip(this.platform)
|
|
79
|
-
const { printLog, processTypeEnum } = this.ctx.helper
|
|
80
|
-
printLog(processTypeEnum.START, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`)
|
|
81
83
|
if (this.projectConfigJson) {
|
|
82
84
|
this.generateProjectConfig(this.projectConfigJson)
|
|
83
85
|
}
|
|
86
|
+
if (this.ctx.initialConfig.logger?.quiet === false) {
|
|
87
|
+
const { printLog, processTypeEnum } = this.ctx.helper
|
|
88
|
+
printLog(processTypeEnum.START, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`)
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
protected emptyOutputDir () {
|
|
@@ -89,21 +95,30 @@ export abstract class TaroPlatformBase {
|
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
protected printDevelopmentTip (platform: string) {
|
|
92
|
-
|
|
98
|
+
const tips: string[] = []
|
|
99
|
+
const config = this.config
|
|
100
|
+
const { chalk } = this.helper
|
|
101
|
+
|
|
102
|
+
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
|
103
|
+
const { isWindows } = this.helper
|
|
104
|
+
const exampleCommand = isWindows
|
|
105
|
+
? `$ set NODE_ENV=production && taro build --type ${platform} --watch`
|
|
106
|
+
: `$ NODE_ENV=production taro build --type ${platform} --watch`
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
tips.push(chalk.yellowBright(`预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
|
|
109
|
+
Example:
|
|
110
|
+
${exampleCommand}`))
|
|
111
|
+
}
|
|
96
112
|
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
exampleCommand = `$ NODE_ENV=production taro build --type ${platform} --watch`
|
|
113
|
+
if (this.compiler === 'webpack5' && !config.cache?.enable) {
|
|
114
|
+
tips.push(chalk.yellowBright('建议开启持久化缓存功能,能有效提升二次编译速度,详情请参考: https://docs.taro.zone/docs/config-detail#cache。'))
|
|
101
115
|
}
|
|
102
116
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
${
|
|
106
|
-
|
|
117
|
+
if (tips.length) {
|
|
118
|
+
console.log(chalk.yellowBright('Tips:'))
|
|
119
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`))
|
|
120
|
+
console.log('\n')
|
|
121
|
+
}
|
|
107
122
|
}
|
|
108
123
|
|
|
109
124
|
/**
|
|
@@ -112,7 +127,18 @@ ${exampleCommand}
|
|
|
112
127
|
protected async getRunner () {
|
|
113
128
|
const { appPath } = this.ctx.paths
|
|
114
129
|
const { npm } = this.helper
|
|
115
|
-
|
|
130
|
+
|
|
131
|
+
let runnerPkg: string
|
|
132
|
+
switch (this.compiler) {
|
|
133
|
+
case 'webpack5':
|
|
134
|
+
runnerPkg = '@tarojs/webpack5-runner'
|
|
135
|
+
break
|
|
136
|
+
default:
|
|
137
|
+
runnerPkg = '@tarojs/mini-runner'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const runner = await npm.getNpmPkg(runnerPkg, appPath)
|
|
141
|
+
|
|
116
142
|
return runner.bind(null, appPath)
|
|
117
143
|
}
|
|
118
144
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { chalk, getModuleDefaultExport } from '@tarojs/helper'
|
|
2
|
+
import type { PluginItem } from '@tarojs/taro/types/compile'
|
|
3
3
|
import { merge } from 'lodash'
|
|
4
|
+
import * as path from 'path'
|
|
4
5
|
import * as resolve from 'resolve'
|
|
5
|
-
import { getModuleDefaultExport, chalk } from '@tarojs/helper'
|
|
6
|
-
|
|
7
|
-
import { PluginItem } from '@tarojs/taro/types/compile'
|
|
8
6
|
|
|
9
7
|
import { PluginType } from './constants'
|
|
10
|
-
import {
|
|
8
|
+
import { IPlugin, IPluginsObject } from './types'
|
|
11
9
|
|
|
12
10
|
export const isNpmPkg: (name: string) => boolean = name => !(/^(\.|\/)/.test(name))
|
|
13
11
|
|
|
@@ -66,7 +64,12 @@ export function resolvePresetsOrPlugins (root: string, args, type: PluginType):
|
|
|
66
64
|
type,
|
|
67
65
|
opts: args[item] || {},
|
|
68
66
|
apply () {
|
|
69
|
-
|
|
67
|
+
try {
|
|
68
|
+
return getModuleDefaultExport(require(fPath))
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error)
|
|
71
|
+
throw new Error(`插件依赖 "${item}" 加载失败,请检查插件配置`)
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
})
|
package/src/utils/types.ts
CHANGED
package/types/index.d.ts
CHANGED