UNPKG

2.59 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11exports.default = (ctx) => {
12 ctx.registerPlatform({
13 name: 'swan',
14 useConfigName: 'mini',
15 fn({ config }) {
16 return __awaiter(this, void 0, void 0, function* () {
17 const { appPath, nodeModulesPath, outputPath } = ctx.paths;
18 const { npm, PARSE_AST_TYPE, emptyDirectory } = ctx.helper;
19 emptyDirectory(outputPath);
20 ctx.generateFrameworkInfo({
21 platform: config.platform
22 });
23 // 生成 project.swan.json
24 ctx.generateProjectConfig({
25 srcConfigName: 'project.swan.json',
26 distConfigName: 'project.swan.json'
27 });
28 // 准备 miniRunner 参数
29 const miniRunnerOpts = Object.assign({}, config, { nodeModulesPath, buildAdapter: config.platform, isBuildPlugin: false, globalObject: 'swan', fileType: {
30 templ: '.swan',
31 style: '.css',
32 config: '.json',
33 script: '.js'
34 }, isUseComponentBuildPage: true });
35 // 百度小程序的页面是由 Component 构造的,需要在页面配置中增加 component: true 配置
36 ctx.modifyBuildTempFileContent(({ tempFiles }) => {
37 Object.keys(tempFiles).forEach(key => {
38 const item = tempFiles[key];
39 if (item.type === PARSE_AST_TYPE.PAGE) {
40 item.config.component = true;
41 }
42 });
43 return tempFiles;
44 });
45 // build with webpack
46 const miniRunner = yield npm.getNpmPkg('@tarojs/mini-runner', appPath);
47 yield miniRunner(appPath, miniRunnerOpts);
48 });
49 }
50 });
51};