@spcsn/taro-service 0.1.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/LICENSE +174 -0
- package/dist/Config.d.ts +21 -0
- package/dist/Config.js +135 -0
- package/dist/Config.js.map +1 -0
- package/dist/Kernel.d.ts +66 -0
- package/dist/Kernel.js +357 -0
- package/dist/Kernel.js.map +1 -0
- package/dist/Plugin.d.ts +15 -0
- package/dist/Plugin.js +73 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/platform-plugin-base/index.d.ts +3 -0
- package/dist/platform-plugin-base/index.js +25 -0
- package/dist/platform-plugin-base/index.js.map +1 -0
- package/dist/platform-plugin-base/mini.d.ts +57 -0
- package/dist/platform-plugin-base/mini.js +165 -0
- package/dist/platform-plugin-base/mini.js.map +1 -0
- package/dist/platform-plugin-base/platform.d.ts +38 -0
- package/dist/platform-plugin-base/platform.js +67 -0
- package/dist/platform-plugin-base/platform.js.map +1 -0
- package/dist/platform-plugin-base/web.d.ts +32 -0
- package/dist/platform-plugin-base/web.js +150 -0
- package/dist/platform-plugin-base/web.js.map +1 -0
- package/dist/platform-plugin-base/webpack/hmr-plugin.d.ts +4 -0
- package/dist/platform-plugin-base/webpack/hmr-plugin.js +37 -0
- package/dist/platform-plugin-base/webpack/hmr-plugin.js.map +1 -0
- package/dist/utils/constants.d.ts +16 -0
- package/dist/utils/constants.js +21 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +186 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/package.d.ts +3 -0
- package/dist/utils/package.js +51 -0
- package/dist/utils/package.js.map +1 -0
- package/dist/utils/types.d.ts +187 -0
- package/dist/utils/types.js +3 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TaroPlatformBase = void 0;
|
|
7
|
+
const taro_helper_1 = require("@spcsn/taro-helper");
|
|
8
|
+
const taro_shared_1 = require("@spcsn/taro-shared");
|
|
9
|
+
const package_1 = require("../utils/package");
|
|
10
|
+
const platform_1 = __importDefault(require("./platform"));
|
|
11
|
+
class TaroPlatformBase extends platform_1.default {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.platformType = taro_shared_1.PLATFORM_TYPE.MINI;
|
|
15
|
+
// Note: 给所有的小程序平台一个默认的 taroComponentsPath
|
|
16
|
+
this.taroComponentsPath = taro_helper_1.taroJsMiniComponentsPath;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 1. 清空 dist 文件夹
|
|
20
|
+
* 2. 输出编译提示
|
|
21
|
+
* 3. 生成 project.config.json
|
|
22
|
+
*/
|
|
23
|
+
async setup() {
|
|
24
|
+
await this.setupTransaction.perform(this.setupImpl, this);
|
|
25
|
+
this.ctx.onSetupClose?.(this);
|
|
26
|
+
}
|
|
27
|
+
setupImpl() {
|
|
28
|
+
const { output } = this.config;
|
|
29
|
+
// webpack5 原生支持 output.clean 选项,但是 webpack4 不支持, 为统一行为,这里做一下兼容
|
|
30
|
+
// (在 packages/taro-mini-runner/src/webpack/chain.ts 和 packages/taro-webpack-runner/src/utils/chain.ts 的 makeConfig 中对 clean 选项做了过滤)
|
|
31
|
+
// 仅 output.clean 为 false 时不清空输出目录
|
|
32
|
+
// eslint-disable-next-line eqeqeq
|
|
33
|
+
if (output == undefined || output.clean == undefined || output.clean === true) {
|
|
34
|
+
this.emptyOutputDir();
|
|
35
|
+
}
|
|
36
|
+
else if ((0, taro_shared_1.isObject)(output.clean)) {
|
|
37
|
+
this.emptyOutputDir(output.clean.keep || []);
|
|
38
|
+
}
|
|
39
|
+
this.printDevelopmentTip(this.platform);
|
|
40
|
+
if (this.projectConfigJson) {
|
|
41
|
+
this.generateProjectConfig(this.projectConfigJson);
|
|
42
|
+
}
|
|
43
|
+
if (this.ctx.initialConfig.logger?.quiet === false) {
|
|
44
|
+
const { printLog, processTypeEnum } = this.ctx.helper;
|
|
45
|
+
printLog("start" /* processTypeEnum.START */, '开发者工具-项目目录', `${this.ctx.paths.outputPath}`);
|
|
46
|
+
}
|
|
47
|
+
// Webpack5 已在 Vite-only fork 中移除,HMR 由 vite-runner 自身负责
|
|
48
|
+
}
|
|
49
|
+
printDevelopmentTip(platform) {
|
|
50
|
+
const tips = [];
|
|
51
|
+
const config = this.config;
|
|
52
|
+
const { chalk } = this.helper;
|
|
53
|
+
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
|
|
54
|
+
const { isWindows } = this.helper;
|
|
55
|
+
const exampleCommand = isWindows
|
|
56
|
+
? `$ set NODE_ENV=production && taro build --type ${platform} --watch`
|
|
57
|
+
: `$ NODE_ENV=production taro build --type ${platform} --watch`;
|
|
58
|
+
tips.push(chalk.yellowBright(`预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
|
|
59
|
+
Example:
|
|
60
|
+
${exampleCommand}`));
|
|
61
|
+
}
|
|
62
|
+
if (this.compiler === 'webpack5' && !config.cache?.enable) {
|
|
63
|
+
tips.push(chalk.yellowBright('webpack5 路径已 deprecated;React-only fork 仅长期维护 vite。'));
|
|
64
|
+
}
|
|
65
|
+
if (tips.length) {
|
|
66
|
+
console.log(chalk.yellowBright('Tips:'));
|
|
67
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`));
|
|
68
|
+
console.log('\n');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 返回当前项目内的 runner 包
|
|
73
|
+
*/
|
|
74
|
+
async getRunner() {
|
|
75
|
+
const { appPath } = this.ctx.paths;
|
|
76
|
+
const { npm } = this.helper;
|
|
77
|
+
const runnerPkg = '@spcsn/taro-vite-runner';
|
|
78
|
+
const runner = await npm.getNpmPkg(runnerPkg, appPath);
|
|
79
|
+
return runner.bind(null, appPath);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 准备 runner 参数
|
|
83
|
+
* @param extraOptions 需要额外合入 Options 的配置项
|
|
84
|
+
*/
|
|
85
|
+
getOptions(extraOptions = {}) {
|
|
86
|
+
const { ctx, globalObject, fileType, template } = this;
|
|
87
|
+
const config = (0, taro_helper_1.recursiveMerge)(Object.assign({}, this.config), {
|
|
88
|
+
env: {
|
|
89
|
+
FRAMEWORK: JSON.stringify(this.config.framework),
|
|
90
|
+
TARO_ENV: JSON.stringify(this.platform),
|
|
91
|
+
TARO_PLATFORM: JSON.stringify(this.platformType),
|
|
92
|
+
TARO_VERSION: JSON.stringify((0, package_1.getPkgVersion)()),
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
...config,
|
|
97
|
+
nodeModulesPath: ctx.paths.nodeModulesPath,
|
|
98
|
+
buildAdapter: config.platform,
|
|
99
|
+
platformType: this.platformType,
|
|
100
|
+
globalObject,
|
|
101
|
+
fileType,
|
|
102
|
+
template,
|
|
103
|
+
...extraOptions,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 调用 runner 开始编译
|
|
108
|
+
* @param extraOptions 需要额外传入 runner 的配置项
|
|
109
|
+
*/
|
|
110
|
+
async build(extraOptions = {}) {
|
|
111
|
+
this.ctx.onBuildInit?.(this);
|
|
112
|
+
await this.buildTransaction.perform(this.buildImpl, this, extraOptions);
|
|
113
|
+
}
|
|
114
|
+
async buildImpl(extraOptions = {}) {
|
|
115
|
+
const runner = await this.getRunner();
|
|
116
|
+
const options = this.getOptions(Object.assign({
|
|
117
|
+
runtimePath: this.runtimePath,
|
|
118
|
+
taroComponentsPath: this.taroComponentsPath,
|
|
119
|
+
behaviorsName: this.behaviorsName,
|
|
120
|
+
}, extraOptions));
|
|
121
|
+
await runner(options);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 生成 project.config.json
|
|
125
|
+
* @param src 项目源码中配置文件的名称
|
|
126
|
+
* @param dist 编译后配置文件的名称,默认为 'project.config.json'
|
|
127
|
+
*/
|
|
128
|
+
generateProjectConfig(src, dist = 'project.config.json') {
|
|
129
|
+
if (this.config.isBuildNativeComp)
|
|
130
|
+
return;
|
|
131
|
+
this.ctx.generateProjectConfig({
|
|
132
|
+
srcConfigName: src,
|
|
133
|
+
distConfigName: dist,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 递归替换对象的 key 值
|
|
138
|
+
*/
|
|
139
|
+
recursiveReplaceObjectKeys(obj, keyMap) {
|
|
140
|
+
Object.keys(obj).forEach((key) => {
|
|
141
|
+
if (keyMap[key]) {
|
|
142
|
+
obj[keyMap[key]] = obj[key];
|
|
143
|
+
if (typeof obj[key] === 'object') {
|
|
144
|
+
this.recursiveReplaceObjectKeys(obj[keyMap[key]], keyMap);
|
|
145
|
+
}
|
|
146
|
+
delete obj[key];
|
|
147
|
+
}
|
|
148
|
+
else if (keyMap[key] === false) {
|
|
149
|
+
delete obj[key];
|
|
150
|
+
}
|
|
151
|
+
else if (typeof obj[key] === 'object') {
|
|
152
|
+
this.recursiveReplaceObjectKeys(obj[key], keyMap);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 调用 runner 开启编译
|
|
158
|
+
*/
|
|
159
|
+
async start() {
|
|
160
|
+
await this.setup();
|
|
161
|
+
await this.build();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.TaroPlatformBase = TaroPlatformBase;
|
|
165
|
+
//# sourceMappingURL=mini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;oBACjC,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC5D,CAAC;gBACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;iBAAM,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;gBACjC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;iBAAM,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACxC,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;YACpD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAhLD,4CAgLC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PLATFORM_TYPE } from '@spcsn/taro-shared';
|
|
2
|
+
import type { Func } from '@spcsn/taro/types/compile';
|
|
3
|
+
import type { IPluginContext, TConfig } from '../utils/types';
|
|
4
|
+
interface IWrapper {
|
|
5
|
+
init?(): void;
|
|
6
|
+
close?(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class Transaction<T = TaroPlatform> {
|
|
9
|
+
wrappers: IWrapper[];
|
|
10
|
+
perform(fn: Func, scope: T, ...args: any[]): Promise<void>;
|
|
11
|
+
initAll(scope: T): void;
|
|
12
|
+
closeAll(scope: T): void;
|
|
13
|
+
addWrapper(wrapper: IWrapper): void;
|
|
14
|
+
}
|
|
15
|
+
export default abstract class TaroPlatform<T extends TConfig = TConfig> {
|
|
16
|
+
protected ctx: IPluginContext;
|
|
17
|
+
protected config: T;
|
|
18
|
+
protected helper: IPluginContext['helper'];
|
|
19
|
+
protected compiler: string;
|
|
20
|
+
abstract platformType: PLATFORM_TYPE;
|
|
21
|
+
abstract platform: string;
|
|
22
|
+
abstract runtimePath: string | string[];
|
|
23
|
+
behaviorsName?: string;
|
|
24
|
+
protected setupTransaction: Transaction<this>;
|
|
25
|
+
protected buildTransaction: Transaction<this>;
|
|
26
|
+
constructor(ctx: IPluginContext, config: T);
|
|
27
|
+
getConfig(): T;
|
|
28
|
+
protected emptyOutputDir(excludes?: Array<string | RegExp>): void;
|
|
29
|
+
/**
|
|
30
|
+
* 如果分端编译详情 webpack 配置了 output 则需更新 outputPath 位置
|
|
31
|
+
*/
|
|
32
|
+
private updateOutputPath;
|
|
33
|
+
/**
|
|
34
|
+
* 调用 runner 开启编译
|
|
35
|
+
*/
|
|
36
|
+
abstract start(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transaction = void 0;
|
|
4
|
+
const VALID_COMPILER = ['webpack5', 'vite'];
|
|
5
|
+
// React-only / Vite-only fork:默认改用 vite,webpack5 仅作兼容路径,后续阶段将整体移除
|
|
6
|
+
const DEFAULT_COMPILER = 'vite';
|
|
7
|
+
const DEPRECATED_COMPILERS = new Set(['webpack5']);
|
|
8
|
+
class Transaction {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.wrappers = [];
|
|
11
|
+
}
|
|
12
|
+
async perform(fn, scope, ...args) {
|
|
13
|
+
this.initAll(scope);
|
|
14
|
+
await fn.call(scope, ...args);
|
|
15
|
+
this.closeAll(scope);
|
|
16
|
+
}
|
|
17
|
+
initAll(scope) {
|
|
18
|
+
const wrappers = this.wrappers;
|
|
19
|
+
wrappers.forEach((wrapper) => wrapper.init?.call(scope));
|
|
20
|
+
}
|
|
21
|
+
closeAll(scope) {
|
|
22
|
+
const wrappers = this.wrappers;
|
|
23
|
+
wrappers.forEach((wrapper) => wrapper.close?.call(scope));
|
|
24
|
+
}
|
|
25
|
+
addWrapper(wrapper) {
|
|
26
|
+
this.wrappers.push(wrapper);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Transaction = Transaction;
|
|
30
|
+
class TaroPlatform {
|
|
31
|
+
constructor(ctx, config) {
|
|
32
|
+
this.setupTransaction = new Transaction();
|
|
33
|
+
this.buildTransaction = new Transaction();
|
|
34
|
+
this.ctx = ctx;
|
|
35
|
+
this.helper = ctx.helper;
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.updateOutputPath(config);
|
|
38
|
+
const _compiler = config.compiler;
|
|
39
|
+
this.compiler = typeof _compiler === 'object' ? _compiler.type : _compiler;
|
|
40
|
+
// Note: 兼容 webpack4 和不填写 compiler 的情况,React-only fork 默认使用 vite
|
|
41
|
+
if (!VALID_COMPILER.includes(this.compiler)) {
|
|
42
|
+
this.compiler = DEFAULT_COMPILER;
|
|
43
|
+
}
|
|
44
|
+
if (DEPRECATED_COMPILERS.has(this.compiler)) {
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn(`[taro] compiler "${this.compiler}" 已被标记为 deprecated,React-only fork 仅长期维护 vite。请在 Taro 配置中切换 compiler 为 "vite"。`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
getConfig() {
|
|
50
|
+
return this.config;
|
|
51
|
+
}
|
|
52
|
+
emptyOutputDir(excludes = []) {
|
|
53
|
+
const { outputPath } = this.ctx.paths;
|
|
54
|
+
this.helper.emptyDirectory(outputPath, { excludes });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 如果分端编译详情 webpack 配置了 output 则需更新 outputPath 位置
|
|
58
|
+
*/
|
|
59
|
+
updateOutputPath(config) {
|
|
60
|
+
const platformPath = config.output?.path;
|
|
61
|
+
if (platformPath) {
|
|
62
|
+
this.ctx.paths.outputPath = platformPath;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = TaroPlatform;
|
|
67
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform-plugin-base/platform.ts"],"names":[],"mappings":";;;AAUA,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC5C,kEAAkE;AAClE,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAEnD,MAAa,WAAW;IAAxB;QACE,aAAQ,GAAe,EAAE,CAAC;IAqB5B,CAAC;IAnBC,KAAK,CAAC,OAAO,CAAC,EAAQ,EAAE,KAAQ,EAAE,GAAG,IAAW;QAC9C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,KAAQ;QACd,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,QAAQ,CAAC,KAAQ;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,UAAU,CAAC,OAAiB;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IA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,CAAC;QACzC,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,GAAG,YAAY,CAAC;QAC3C,CAAC;IACH,CAAC;CAMF;AAzDD,+BAyDC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PLATFORM_TYPE } from '@spcsn/taro-shared';
|
|
2
|
+
import TaroPlatform from './platform';
|
|
3
|
+
import type { TConfig } from '../utils/types';
|
|
4
|
+
export declare abstract class TaroPlatformWeb<T extends TConfig = TConfig> extends TaroPlatform<T> {
|
|
5
|
+
platformType: PLATFORM_TYPE;
|
|
6
|
+
/**
|
|
7
|
+
* 1. 清空 dist 文件夹
|
|
8
|
+
* 2. 输出编译提示
|
|
9
|
+
*/
|
|
10
|
+
private setup;
|
|
11
|
+
private setupWebApp;
|
|
12
|
+
protected printDevelopmentTip(): void;
|
|
13
|
+
/**
|
|
14
|
+
* 返回当前项目内的 runner 包
|
|
15
|
+
*/
|
|
16
|
+
protected getRunner(): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* 准备 runner 参数
|
|
19
|
+
* @param extraOptions 需要额外合入 Options 的配置项
|
|
20
|
+
*/
|
|
21
|
+
protected getOptions(extraOptions?: {}): any;
|
|
22
|
+
/**
|
|
23
|
+
* 调用 runner 开始编译
|
|
24
|
+
* @param extraOptions 需要额外传入 runner 的配置项
|
|
25
|
+
*/
|
|
26
|
+
private build;
|
|
27
|
+
private buildWebApp;
|
|
28
|
+
/**
|
|
29
|
+
* 调用 runner 开启编译
|
|
30
|
+
*/
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TaroPlatformWeb = void 0;
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
const taro_shared_1 = require("@spcsn/taro-shared");
|
|
42
|
+
const lodash_1 = require("lodash");
|
|
43
|
+
const package_1 = require("../utils/package");
|
|
44
|
+
const platform_1 = __importDefault(require("./platform"));
|
|
45
|
+
class TaroPlatformWeb extends platform_1.default {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
this.platformType = taro_shared_1.PLATFORM_TYPE.WEB;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 1. 清空 dist 文件夹
|
|
52
|
+
* 2. 输出编译提示
|
|
53
|
+
*/
|
|
54
|
+
async setup() {
|
|
55
|
+
await this.setupTransaction.perform(this.setupWebApp, this);
|
|
56
|
+
this.ctx.onSetupClose?.(this);
|
|
57
|
+
}
|
|
58
|
+
setupWebApp() {
|
|
59
|
+
const { output } = this.config;
|
|
60
|
+
// webpack5 原生支持 output.clean 选项,但是 webpack4 不支持, 为统一行为,这里做一下兼容
|
|
61
|
+
// (在 packages/taro-mini-runner/src/webpack/chain.ts 和 packages/taro-webpack-runner/src/utils/chain.ts 的 makeConfig 中对 clean 选项做了过滤)
|
|
62
|
+
// eslint-disable-next-line eqeqeq
|
|
63
|
+
if (output == undefined || output.clean == undefined || output.clean === true) {
|
|
64
|
+
this.emptyOutputDir();
|
|
65
|
+
}
|
|
66
|
+
else if ((0, taro_shared_1.isObject)(output.clean)) {
|
|
67
|
+
this.emptyOutputDir(output.clean.keep || []);
|
|
68
|
+
}
|
|
69
|
+
this.printDevelopmentTip();
|
|
70
|
+
}
|
|
71
|
+
printDevelopmentTip() {
|
|
72
|
+
const tips = [];
|
|
73
|
+
if (tips.length) {
|
|
74
|
+
const { chalk } = this.helper;
|
|
75
|
+
console.log(chalk.yellowBright('Tips:'));
|
|
76
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`));
|
|
77
|
+
console.log('\n');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 返回当前项目内的 runner 包
|
|
82
|
+
*/
|
|
83
|
+
async getRunner() {
|
|
84
|
+
const { appPath } = this.ctx.paths;
|
|
85
|
+
const { npm } = this.helper;
|
|
86
|
+
// React-only / Vite-only fork:webpack5 路径已移除,runner 固定为 vite-runner
|
|
87
|
+
const runnerPkg = '@spcsn/taro-vite-runner';
|
|
88
|
+
const runner = await npm.getNpmPkg(runnerPkg, appPath);
|
|
89
|
+
return runner.bind(null, appPath);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 准备 runner 参数
|
|
93
|
+
* @param extraOptions 需要额外合入 Options 的配置项
|
|
94
|
+
*/
|
|
95
|
+
getOptions(extraOptions = {}) {
|
|
96
|
+
const { sourcePath } = this.ctx.paths;
|
|
97
|
+
const { initialConfig } = this.ctx;
|
|
98
|
+
const { port } = this.ctx.runOpts.options;
|
|
99
|
+
const { recursiveMerge, ENTRY, SOURCE_DIR, OUTPUT_DIR } = this.ctx.helper;
|
|
100
|
+
const entryFileName = `${ENTRY}.config`;
|
|
101
|
+
const entryFile = path.basename(entryFileName);
|
|
102
|
+
const defaultEntry = {
|
|
103
|
+
[ENTRY]: [path.join(sourcePath, entryFile)],
|
|
104
|
+
};
|
|
105
|
+
const customEntry = (0, lodash_1.get)(initialConfig, 'h5.entry');
|
|
106
|
+
const config = recursiveMerge(Object.assign({}, this.config), {
|
|
107
|
+
entryFileName: ENTRY,
|
|
108
|
+
env: {
|
|
109
|
+
FRAMEWORK: JSON.stringify(this.config.framework),
|
|
110
|
+
TARO_ENV: JSON.stringify(this.platform),
|
|
111
|
+
TARO_PLATFORM: JSON.stringify(this.platformType),
|
|
112
|
+
TARO_VERSION: JSON.stringify((0, package_1.getPkgVersion)()),
|
|
113
|
+
},
|
|
114
|
+
devServer: { port },
|
|
115
|
+
sourceRoot: this.config.sourceRoot || SOURCE_DIR,
|
|
116
|
+
outputRoot: this.config.outputRoot || OUTPUT_DIR,
|
|
117
|
+
});
|
|
118
|
+
config.entry = (0, lodash_1.merge)(defaultEntry, customEntry);
|
|
119
|
+
return {
|
|
120
|
+
...config,
|
|
121
|
+
buildAdapter: config.platform,
|
|
122
|
+
platformType: this.platformType,
|
|
123
|
+
...extraOptions,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 调用 runner 开始编译
|
|
128
|
+
* @param extraOptions 需要额外传入 runner 的配置项
|
|
129
|
+
*/
|
|
130
|
+
async build(extraOptions = {}) {
|
|
131
|
+
this.ctx.onBuildInit?.(this);
|
|
132
|
+
await this.buildTransaction.perform(this.buildWebApp, this, extraOptions);
|
|
133
|
+
}
|
|
134
|
+
async buildWebApp(extraOptions = {}) {
|
|
135
|
+
const runner = await this.getRunner();
|
|
136
|
+
const options = this.getOptions(Object.assign({
|
|
137
|
+
runtimePath: this.runtimePath,
|
|
138
|
+
}, extraOptions));
|
|
139
|
+
await runner(options);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 调用 runner 开启编译
|
|
143
|
+
*/
|
|
144
|
+
async start() {
|
|
145
|
+
await this.setup();
|
|
146
|
+
await this.build();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.TaroPlatformWeb = TaroPlatformWeb;
|
|
150
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/platform-plugin-base/web.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAElC,oDAA6D;AAC7D,mCAAoC;AAEpC,8CAAiD;AACjD,0DAAsC;AAItC,MAAsB,eAA6C,SAAQ,kBAAe;IAA1F;;QACE,iBAAY,GAAG,2BAAa,CAAC,GAAG,CAAC;IAoHnC,CAAC;IAlHC;;;OAGG;IACK,KAAK,CAAC,KAAK;QACjB,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAEO,WAAW;QACjB,MAAM,EAAE,M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+
apply(compiler) {
|
|
5
|
+
compiler.hooks.thisCompilation.tap('TaroMiniHMRPlugin', (compilation) => {
|
|
6
|
+
compilation.hooks.beforeChunkAssets.tap('TaroMiniHMRPlugin', () => {
|
|
7
|
+
compilation.chunks.forEach((chunk) => {
|
|
8
|
+
if (chunk.hasRuntime() && chunk.name === 'runtime') {
|
|
9
|
+
const runtimeModules = compilation.chunkGraph.getChunkRuntimeModulesInOrder(chunk);
|
|
10
|
+
for (const module of runtimeModules) {
|
|
11
|
+
if (module.name === 'jsonp chunk loading') {
|
|
12
|
+
const runtimeSource = compilation.codeGenerationResults.getSource(module, chunk.runtime, 'runtime');
|
|
13
|
+
runtimeSource['_value'] += `
|
|
14
|
+
var miniHMRCallback = function(parentChunkLoadingFunction, data) {
|
|
15
|
+
var chunkIds = data[0];
|
|
16
|
+
var moreModules = data[1];
|
|
17
|
+
if(chunkIds.some(function(id) { return installedChunks[id] === 0 })) {
|
|
18
|
+
chunkIds.forEach(id => {
|
|
19
|
+
delete installedChunks[id]
|
|
20
|
+
})
|
|
21
|
+
Object.keys(moreModules).forEach(id => {
|
|
22
|
+
delete __webpack_module_cache__[id]
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
|
|
26
|
+
}
|
|
27
|
+
chunkLoadingGlobal.push = miniHMRCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.default = TaroMiniHMRPlugin;
|
|
37
|
+
//# sourceMappingURL=hmr-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr-plugin.js","sourceRoot":"","sources":["../../../src/platform-plugin-base/webpack/hmr-plugin.ts"],"names":[],"mappings":";;AAGA,MAAqB,iBAAiB;IACpC,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,WAAW,EAAE,EAAE;YACtE,WAAW,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,EAAE;gBAChE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBACnC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;wBACnD,MAAM,cAAc,GAAG,WAAW,CAAC,UAAU,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC;wBACnF,KAAK,MAAM,MAAM,IAAI,cAAc,EAAE,CAAC;4BACpC,IAAI,MAAM,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gCAC1C,MAAM,aAAa,GAAG,WAAW,CAAC,qBAAqB,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gCACpG,aAAa,CAAC,QAAQ,CAAC,IAAI;;;;;;;;;;;;;;wGAc6D,CAAC;4BAC3F,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhCD,oCAgCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const CONFIG_DIR_NAME = "config";
|
|
2
|
+
export declare const DEFAULT_CONFIG_FILE = "index";
|
|
3
|
+
export declare const PRESET_PREFIX = "@spcsn/taro-preset-";
|
|
4
|
+
export declare const PLUGIN_PREFIX = "@spcsn/taro-plugin-";
|
|
5
|
+
export declare const IS_EVENT_HOOK: RegExp;
|
|
6
|
+
export declare const IS_ADD_HOOK: RegExp;
|
|
7
|
+
export declare const IS_MODIFY_HOOK: RegExp;
|
|
8
|
+
export declare const presetOrPluginPrefixReg: RegExp;
|
|
9
|
+
export declare enum PluginType {
|
|
10
|
+
Preset = "Preset",
|
|
11
|
+
Plugin = "Plugin"
|
|
12
|
+
}
|
|
13
|
+
export declare const PluginNamePrefix: {
|
|
14
|
+
Preset: string;
|
|
15
|
+
Plugin: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginNamePrefix = exports.PluginType = exports.presetOrPluginPrefixReg = exports.IS_MODIFY_HOOK = exports.IS_ADD_HOOK = exports.IS_EVENT_HOOK = exports.PLUGIN_PREFIX = exports.PRESET_PREFIX = exports.DEFAULT_CONFIG_FILE = exports.CONFIG_DIR_NAME = void 0;
|
|
4
|
+
exports.CONFIG_DIR_NAME = 'config';
|
|
5
|
+
exports.DEFAULT_CONFIG_FILE = 'index';
|
|
6
|
+
exports.PRESET_PREFIX = '@spcsn/taro-preset-';
|
|
7
|
+
exports.PLUGIN_PREFIX = '@spcsn/taro-plugin-';
|
|
8
|
+
exports.IS_EVENT_HOOK = /^on/;
|
|
9
|
+
exports.IS_ADD_HOOK = /^add/;
|
|
10
|
+
exports.IS_MODIFY_HOOK = /^modify/;
|
|
11
|
+
exports.presetOrPluginPrefixReg = new RegExp(`^${exports.PRESET_PREFIX}|${exports.PLUGIN_PREFIX}`);
|
|
12
|
+
var PluginType;
|
|
13
|
+
(function (PluginType) {
|
|
14
|
+
PluginType["Preset"] = "Preset";
|
|
15
|
+
PluginType["Plugin"] = "Plugin";
|
|
16
|
+
})(PluginType || (exports.PluginType = PluginType = {}));
|
|
17
|
+
exports.PluginNamePrefix = {
|
|
18
|
+
[PluginType.Preset]: exports.PLUGIN_PREFIX,
|
|
19
|
+
[PluginType.Plugin]: exports.PLUGIN_PREFIX,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,mBAAmB,GAAG,OAAO,CAAC;AAE9B,QAAA,aAAa,GAAG,qBAAqB,CAAC;AACtC,QAAA,aAAa,GAAG,qBAAqB,CAAC;AAEtC,QAAA,aAAa,GAAG,KAAK,CAAC;AACtB,QAAA,WAAW,GAAG,MAAM,CAAC;AACrB,QAAA,cAAc,GAAG,SAAS,CAAC;AAE3B,QAAA,uBAAuB,GAAG,IAAI,MAAM,CAAC,IAAI,qBAAa,IAAI,qBAAa,EAAE,CAAC,CAAC;AAExF,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;AACnB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAEY,QAAA,gBAAgB,GAAG;IAC9B,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,qBAAa;IAClC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,qBAAa;CACnC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PluginType } from './constants';
|
|
2
|
+
import type { IProjectConfig, PluginItem } from '@spcsn/taro/types/compile';
|
|
3
|
+
import type { IPlugin, IPluginsObject } from './types';
|
|
4
|
+
export declare const isNpmPkg: (name: string) => boolean;
|
|
5
|
+
export declare function getPluginPath(pluginPath: string): string;
|
|
6
|
+
export declare function convertPluginsToObject(items: PluginItem[]): () => IPluginsObject;
|
|
7
|
+
export declare function mergePlugins(dist: PluginItem[], src: PluginItem[]): () => IPluginsObject;
|
|
8
|
+
export declare function resolvePresetsOrPlugins(root: string, args: IPluginsObject, type: PluginType, skipError?: boolean): IPlugin[];
|
|
9
|
+
export declare function printHelpLog(command: any, optionsList: Map<string, string>, synopsisList?: Set<string>): void;
|
|
10
|
+
export declare function filterGlobalConfig(globalConfig: IProjectConfig, command: string): IProjectConfig<"webpack5">;
|