@tarojs/service 3.4.5 → 3.5.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/dist/Config.js +2 -2
- package/dist/Kernel.js +2 -2
- package/dist/platform-plugin-base.d.ts +1 -0
- package/dist/platform-plugin-base.js +35 -15
- package/package.json +8 -8
- package/src/Config.ts +8 -2
- package/src/Kernel.ts +3 -3
- package/src/platform-plugin-base.ts +39 -14
- package/types/index.d.ts +1 -1
package/dist/Config.js
CHANGED
|
@@ -17,7 +17,7 @@ class Config {
|
|
|
17
17
|
this.isInitSuccess = false;
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
helper_1.
|
|
20
|
+
helper_1.createSwcRegister({
|
|
21
21
|
only: [
|
|
22
22
|
filePath => filePath.indexOf(path.join(this.appPath, constants_1.CONFIG_DIR_NAME)) >= 0
|
|
23
23
|
]
|
|
@@ -43,7 +43,7 @@ class Config {
|
|
|
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.js
CHANGED
|
@@ -65,7 +65,7 @@ class Kernel extends events_1.EventEmitter {
|
|
|
65
65
|
const allConfigPlugins = utils_1.mergePlugins(this.optsPlugins || [], initialConfig.plugins || [])();
|
|
66
66
|
this.debugger('initPresetsAndPlugins', allConfigPresets, allConfigPlugins);
|
|
67
67
|
process.env.NODE_ENV !== 'test' &&
|
|
68
|
-
helper_1.
|
|
68
|
+
helper_1.createSwcRegister({
|
|
69
69
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
70
70
|
});
|
|
71
71
|
this.plugins = new Map();
|
|
@@ -115,7 +115,7 @@ class Kernel extends events_1.EventEmitter {
|
|
|
115
115
|
if (typeof pluginCtx.optsSchema !== 'function') {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
const joi = require('
|
|
118
|
+
const joi = require('joi');
|
|
119
119
|
const schema = pluginCtx.optsSchema(joi);
|
|
120
120
|
if (!joi.isSchema(schema)) {
|
|
121
121
|
throw new Error(`插件${pluginCtx.id}中设置参数检查 schema 有误,请检查!`);
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/service",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-alpha.0",
|
|
4
4
|
"description": "Taro Service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@tarojs/
|
|
38
|
-
"@tarojs/
|
|
39
|
-
"
|
|
40
|
-
"
|
|
36
|
+
"@tarojs/helper": "3.5.0-alpha.0",
|
|
37
|
+
"@tarojs/shared": "3.5.0-alpha.0",
|
|
38
|
+
"@tarojs/taro": "3.5.0-alpha.0",
|
|
39
|
+
"fs-extra": "^8.1.0",
|
|
40
|
+
"joi": "^17.6.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
|
-
"resolve": "^1.
|
|
42
|
+
"resolve": "^1.22.0",
|
|
43
43
|
"tapable": "^1.1.3",
|
|
44
44
|
"webpack-merge": "^4.2.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "8b2acf55c5f98e54bb2788a723a2ef0e0a1b75b6"
|
|
47
47
|
}
|
package/src/Config.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
OUTPUT_DIR,
|
|
9
9
|
ENTRY,
|
|
10
10
|
resolveScriptPath,
|
|
11
|
-
|
|
11
|
+
createSwcRegister,
|
|
12
12
|
getModuleDefaultExport
|
|
13
13
|
} from '@tarojs/helper'
|
|
14
14
|
|
|
@@ -37,7 +37,7 @@ export default class Config {
|
|
|
37
37
|
this.initialConfig = {}
|
|
38
38
|
this.isInitSuccess = false
|
|
39
39
|
} else {
|
|
40
|
-
|
|
40
|
+
createSwcRegister({
|
|
41
41
|
only: [
|
|
42
42
|
filePath => filePath.indexOf(path.join(this.appPath, CONFIG_DIR_NAME)) >= 0
|
|
43
43
|
]
|
|
@@ -73,6 +73,9 @@ export default class Config {
|
|
|
73
73
|
outputRoot: outputDirName,
|
|
74
74
|
platform,
|
|
75
75
|
framework: initialConfig.framework,
|
|
76
|
+
compiler: initialConfig.compiler,
|
|
77
|
+
cache: initialConfig.cache,
|
|
78
|
+
logger: initialConfig.logger,
|
|
76
79
|
baseLevel: initialConfig.baseLevel,
|
|
77
80
|
csso: initialConfig.csso,
|
|
78
81
|
sass: initialConfig.sass,
|
|
@@ -84,7 +87,10 @@ export default class Config {
|
|
|
84
87
|
designWidth: initialConfig.designWidth,
|
|
85
88
|
deviceRatio: initialConfig.deviceRatio,
|
|
86
89
|
projectConfigName: initialConfig.projectConfigName,
|
|
90
|
+
jsMinimizer: initialConfig.jsMinimizer,
|
|
91
|
+
cssMinimizer: initialConfig.cssMinimizer,
|
|
87
92
|
terser: initialConfig.terser,
|
|
93
|
+
esbuild: initialConfig.esbuild,
|
|
88
94
|
...initialConfig[useConfigName]
|
|
89
95
|
}
|
|
90
96
|
}
|
package/src/Kernel.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile'
|
|
|
6
6
|
import {
|
|
7
7
|
NODE_MODULES,
|
|
8
8
|
recursiveFindNodeModules,
|
|
9
|
-
|
|
9
|
+
createSwcRegister,
|
|
10
10
|
createDebug
|
|
11
11
|
} from '@tarojs/helper'
|
|
12
12
|
import * as helper from '@tarojs/helper'
|
|
@@ -104,7 +104,7 @@ export default class Kernel extends EventEmitter {
|
|
|
104
104
|
const allConfigPlugins = mergePlugins(this.optsPlugins || [], initialConfig.plugins || [])()
|
|
105
105
|
this.debugger('initPresetsAndPlugins', allConfigPresets, allConfigPlugins)
|
|
106
106
|
process.env.NODE_ENV !== 'test' &&
|
|
107
|
-
|
|
107
|
+
createSwcRegister({
|
|
108
108
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
109
109
|
})
|
|
110
110
|
this.plugins = new Map()
|
|
@@ -160,7 +160,7 @@ export default class Kernel extends EventEmitter {
|
|
|
160
160
|
if (typeof pluginCtx.optsSchema !== 'function') {
|
|
161
161
|
return
|
|
162
162
|
}
|
|
163
|
-
const joi = require('
|
|
163
|
+
const joi = require('joi')
|
|
164
164
|
const schema = pluginCtx.optsSchema(joi)
|
|
165
165
|
if (!joi.isSchema(schema)) {
|
|
166
166
|
throw new Error(`插件${pluginCtx.id}中设置参数检查 schema 有误,请检查!`)
|
|
@@ -42,6 +42,7 @@ export abstract class TaroPlatformBase {
|
|
|
42
42
|
ctx: IPluginContext
|
|
43
43
|
helper: IPluginContext['helper']
|
|
44
44
|
config: any
|
|
45
|
+
compiler: string
|
|
45
46
|
|
|
46
47
|
abstract platform: string
|
|
47
48
|
abstract globalObject: string
|
|
@@ -58,6 +59,8 @@ export abstract class TaroPlatformBase {
|
|
|
58
59
|
this.ctx = ctx
|
|
59
60
|
this.helper = ctx.helper
|
|
60
61
|
this.config = config
|
|
62
|
+
const _compiler = config.compiler
|
|
63
|
+
this.compiler = typeof _compiler === 'object' ? _compiler.type : _compiler
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
/**
|
|
@@ -76,11 +79,13 @@ export abstract class TaroPlatformBase {
|
|
|
76
79
|
this.emptyOutputDir()
|
|
77
80
|
}
|
|
78
81
|
this.printDevelopmentTip(this.platform)
|
|
79
|
-
const { printLog, processTypeEnum } = this.ctx.helper
|
|
80
|
-
printLog(processTypeEnum.START, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`)
|
|
81
82
|
if (this.projectConfigJson) {
|
|
82
83
|
this.generateProjectConfig(this.projectConfigJson)
|
|
83
84
|
}
|
|
85
|
+
if (this.ctx.initialConfig.logger?.quiet === false) {
|
|
86
|
+
const { printLog, processTypeEnum } = this.ctx.helper
|
|
87
|
+
printLog(processTypeEnum.START, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`)
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
protected emptyOutputDir () {
|
|
@@ -89,21 +94,30 @@ export abstract class TaroPlatformBase {
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
protected printDevelopmentTip (platform: string) {
|
|
92
|
-
|
|
97
|
+
const tips: string[] = []
|
|
98
|
+
const config = this.config
|
|
99
|
+
const { chalk } = this.helper
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
|
102
|
+
const { isWindows } = this.helper
|
|
103
|
+
const exampleCommand = isWindows
|
|
104
|
+
? `$ set NODE_ENV=production && taro build --type ${platform} --watch`
|
|
105
|
+
: `$ NODE_ENV=production taro build --type ${platform} --watch`
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
exampleCommand = `$ NODE_ENV=production taro build --type ${platform} --watch`
|
|
107
|
+
tips.push(chalk.yellowBright(`预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
|
|
108
|
+
Example:
|
|
109
|
+
${exampleCommand}`))
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
if (this.compiler === 'webpack5' && !config.cache?.enable) {
|
|
113
|
+
tips.push(chalk.yellowBright('建议开启持久化缓存功能,能有效提升二次编译速度,详情请参考: https://docs.taro.zone/docs/config-detail#cache。'))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (tips.length) {
|
|
117
|
+
console.log(chalk.yellowBright('Tips:'))
|
|
118
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`))
|
|
119
|
+
console.log('\n')
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
/**
|
|
@@ -112,7 +126,18 @@ ${exampleCommand}
|
|
|
112
126
|
protected async getRunner () {
|
|
113
127
|
const { appPath } = this.ctx.paths
|
|
114
128
|
const { npm } = this.helper
|
|
115
|
-
|
|
129
|
+
|
|
130
|
+
let runnerPkg: string
|
|
131
|
+
switch (this.compiler) {
|
|
132
|
+
case 'webpack5':
|
|
133
|
+
runnerPkg = '@tarojs/webpack5-runner'
|
|
134
|
+
break
|
|
135
|
+
default:
|
|
136
|
+
runnerPkg = '@tarojs/mini-runner'
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const runner = await npm.getNpmPkg(runnerPkg, appPath)
|
|
140
|
+
|
|
116
141
|
return runner.bind(null, appPath)
|
|
117
142
|
}
|
|
118
143
|
|
package/types/index.d.ts
CHANGED