@cloudbase/lowcode-builder 1.9.0 → 1.9.2

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.
@@ -12,14 +12,14 @@ const BASE_DEPS = {
12
12
  * 注意锁版本
13
13
  */
14
14
  const CLOUDBASE_DEPS = {
15
- '@cloudbase/oauth': '0.1.1-alpha.14',
16
- '@cloudbase/weda-client': '1.1.5',
17
- '@cloudbase/weda-cloud-sdk': '1.0.68',
15
+ '@cloudbase/oauth': '0.1.1-alpha.15',
16
+ '@cloudbase/weda-client': '1.1.6',
17
+ '@cloudbase/weda-cloud-sdk': '1.0.70',
18
18
  };
19
19
  function generatePackageDependencies({ importJSSDK, mode, officialLibVersion, uin, }) {
20
20
  const deps = {};
21
21
  if (importJSSDK) {
22
- deps['@cloudbase/js-sdk'] = '2.5.46-beta.0';
22
+ deps['@cloudbase/js-sdk'] = '2.5.47-beta.0';
23
23
  }
24
24
  const mod = uin ? Number(uin) % 10 : undefined;
25
25
  if (mode === 'lib') {
@@ -17,6 +17,7 @@ const net_1 = require("../util/net");
17
17
  const config_1 = require("../config");
18
18
  const axios_1 = __importDefault(require("axios"));
19
19
  const materials_1 = require("../mp/materials");
20
+ const common_3 = require("@cloudbase/lowcode-generator/lib/generator/types/common");
20
21
  const pkg = require('../../../package.json');
21
22
  async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
22
23
  if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
@@ -101,6 +102,7 @@ async function buildWedaApp({ cals, subAppCalsList: _subAppCalsList = [], depend
101
102
  runtimeDynamicConfig = data;
102
103
  }
103
104
  }
105
+ const officialLib = dependencies.find((item) => item.name === cals_1.OFFICIAL_LIB_KEY);
104
106
  const buildContext = {
105
107
  uin: account === null || account === void 0 ? void 0 : account.uin,
106
108
  projDir: appBuildDir,
@@ -119,6 +121,7 @@ async function buildWedaApp({ cals, subAppCalsList: _subAppCalsList = [], depend
119
121
  disabled: (_c = cals.extra) === null || _c === void 0 ? void 0 : _c.disabled,
120
122
  statusPageId: ((_d = cals.extra) === null || _d === void 0 ? void 0 : _d.statusPageId) || undefined,
121
123
  privatelinkConfig: privatelinkConfig ? { uin: account === null || account === void 0 ? void 0 : account.uin, ...privatelinkConfig } : undefined,
124
+ enableOfficialLibNPM: !!((0, common_3.buildAsLibByBuildType)(buildTypeList) && officialLib),
122
125
  };
123
126
  console.log('domain', domain);
124
127
  console.log('应用名', appKey);
@@ -309,6 +312,7 @@ function normalizeInputs(inputs, { envId, getWebRootPath, }) {
309
312
  deployOptions: inputs.deployOptions,
310
313
  appId: inputs.appId || inputs.appKey,
311
314
  getWebRootPath: getWebRootPath || _getWebRootPath,
315
+ webOptions: inputs.webOptions,
312
316
  };
313
317
  if (inputs.mainAppSerializeData) {
314
318
  inputs.mainAppSerializeData = normalizeCals(inputs.mainAppSerializeData, normalizeCalsOptions);
@@ -345,7 +349,7 @@ function normalizeInputs(inputs, { envId, getWebRootPath, }) {
345
349
  return inputs;
346
350
  }
347
351
  exports.normalizeInputs = normalizeInputs;
348
- function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWebRootPath }) {
352
+ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWebRootPath, webOptions }) {
349
353
  var _a;
350
354
  if (!cals.extra) {
351
355
  cals.extra = {};
@@ -365,6 +369,7 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
365
369
  if (cals.extra.miniprogramPlugins) {
366
370
  cals.extra.miniprogramPlugins = [];
367
371
  }
372
+ const { gatewayConfig = {} } = webOptions || {};
368
373
  let { appConfig = {} } = cals.extra;
369
374
  let { window = {} } = appConfig;
370
375
  let path = getWebRootPath({ appId, name: cals.name, deployOptions });
@@ -380,7 +385,7 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
380
385
  ? `app/${appId}${(deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) !== types_1.DEPLOY_MODE.UPLOAD ? '-preview' : ''}`
381
386
  : (0, common_1.buildAsXPageByBuildType)(buildTypeList)
382
387
  ? '/'
383
- : path,
388
+ : gatewayConfig.path || path,
384
389
  },
385
390
  };
386
391
  }
@@ -44,7 +44,6 @@ async function runCopy(appBuildDir, webRuntimeAppData, i18nConfig) {
44
44
  const dstFile = path.join(appBuildDir, entry);
45
45
  await fs_extra_1.default.copy(path.join(config_1.appTemplateDir, entry), dstFile);
46
46
  }
47
- await (0, generateFiles_1.writeFile)(path.join(appBuildDir, 'mainAppData.json'), JSON.stringify(webRuntimeAppData, null, 2));
48
47
  const fileDir = path.join(appBuildDir, 'src/i18n/');
49
48
  if (!fs_extra_1.default.existsSync(fileDir)) {
50
49
  fs_extra_1.default.mkdirSync(fileDir, { recursive: true });
@@ -45,14 +45,17 @@ const config_1 = require("../config");
45
45
  const fs_extra_1 = __importDefault(require("fs-extra"));
46
46
  const junk = __importStar(require("../util/junk"));
47
47
  const url_1 = require("url");
48
+ const semver = __importStar(require("semver"));
49
+ const lodash_1 = require("lodash");
50
+ const common_3 = require("@cloudbase/lowcode-generator/lib/generator/types/common");
48
51
  let BabelTransform = (code, options) => code;
49
52
  if (!process.env.IS_WEB_WORKER) {
50
53
  let transform = require('../../utils/transform');
51
54
  BabelTransform = transform.BabelTransform;
52
55
  }
53
56
  async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, ignoreInstall = false, cdnEndpoints, }) {
54
- var _a, _b, _c, _d, _e, _f;
55
- const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode, enableExpiredTag, privatelinkConfig, } = buildContext;
57
+ var _a, _b, _c, _d, _e, _f, _g, _h;
58
+ const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode, enableExpiredTag, privatelinkConfig, enableOfficialLibNPM, } = buildContext;
56
59
  if (!deployOptions.mode || deployOptions.mode === types_1.DEPLOY_MODE.DYNAMIC) {
57
60
  deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
58
61
  }
@@ -79,17 +82,23 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
79
82
  var _a;
80
83
  return (_a = used.component['$template']) === null || _a === void 0 ? void 0 : _a.has(item.id);
81
84
  });
85
+ const officialLib = dependencies.find((lib) => lib.name === config_1.OFFICIAL_LIB_KEY);
86
+ if (enableOfficialLibNPM) {
87
+ if (!((_d = (_c = cals.extra) === null || _c === void 0 ? void 0 : _c.npmDependencies) === null || _d === void 0 ? void 0 : _d[cals_1.OFFICIAL_LIB_NPM_PACKAGENAME])) {
88
+ (0, lodash_1.set)(cals, `extra.npmDependencies.${cals_1.OFFICIAL_LIB_NPM_PACKAGENAME}`, officialLib === null || officialLib === void 0 ? void 0 : officialLib.version);
89
+ }
90
+ }
82
91
  // 处理应用数据
83
92
  const mainAppData = (0, weapps_core_1.deserialize)((0, common_2.processCals2WeappsData)(cals, dependencies));
84
93
  if (!mainAppData.extra) {
85
94
  mainAppData.extra = { domain };
86
95
  }
87
- if (!((_c = mainAppData.extra) === null || _c === void 0 ? void 0 : _c.domain)) {
96
+ if (!((_e = mainAppData.extra) === null || _e === void 0 ? void 0 : _e.domain)) {
88
97
  mainAppData.extra.domain = domain;
89
98
  }
90
- const subAppDataList = ((_d = subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map) === null || _d === void 0 ? void 0 : _d.call(subAppCalsList, (sub) => (0, weapps_core_1.deserialize)((0, common_2.processCals2WeappsData)(sub, dependencies)))) || [];
99
+ const subAppDataList = ((_f = subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map) === null || _f === void 0 ? void 0 : _f.call(subAppCalsList, (sub) => (0, weapps_core_1.deserialize)((0, common_2.processCals2WeappsData)(sub, dependencies)))) || [];
91
100
  // 前置操作
92
- const { publicPath, basename, assets = '', _indexPage } = ((_e = mainAppData.appConfig) === null || _e === void 0 ? void 0 : _e.window) || {};
101
+ const { publicPath, basename, assets = '', _indexPage } = ((_g = mainAppData.appConfig) === null || _g === void 0 ? void 0 : _g.window) || {};
93
102
  // 获取 插入的cdn 资源
94
103
  const jsAssets = await (0, generate_1.handleAssets)({
95
104
  appBuildDir: buildDir,
@@ -106,6 +115,48 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
106
115
  // 注意需要包涵官方的(gsd),部分平台方法需要由其补充
107
116
  return lib.name === config_1.OFFICIAL_LIB_KEY || !!(((_a = used.component) === null || _a === void 0 ? void 0 : _a[lib.name]) || ((_b = used.action) === null || _b === void 0 ? void 0 : _b[lib.name]));
108
117
  }), materialsDir, runtime, ignoreInstall);
118
+ if (enableOfficialLibNPM) {
119
+ await fs_extra_1.default.remove(path_1.default.join(h5BuildDir, 'src', 'libraries', `${officialLib === null || officialLib === void 0 ? void 0 : officialLib.name}@${officialLib === null || officialLib === void 0 ? void 0 : officialLib.version}`));
120
+ }
121
+ const h5LibDirPath = path_1.default.resolve(h5BuildDir, 'src', 'libraries');
122
+ const libNames = fs_extra_1.default.readdirSync(h5LibDirPath).filter((name) => name !== '.DS_Store');
123
+ let libNameWithVue;
124
+ const vueVersions = libNames.map((libName) => {
125
+ var _a, _b;
126
+ try {
127
+ const v = (_b = (_a = require(path_1.default.resolve(h5LibDirPath, libName, 'package.json'))) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.vue;
128
+ if (v == null) {
129
+ return 0;
130
+ }
131
+ const minValidVersion = semver.valid(semver.minVersion(v));
132
+ if (minValidVersion == null) {
133
+ return 0;
134
+ }
135
+ libNameWithVue = libName;
136
+ return semver.gt(minValidVersion, '2.7.16') ? 3 : 2;
137
+ }
138
+ catch (e) {
139
+ console.log(e, `no package.json for ${libName}`);
140
+ return 0;
141
+ }
142
+ });
143
+ let vueVersion;
144
+ const vueVersionSet = new Set(vueVersions.filter((v) => v !== 0));
145
+ if (vueVersionSet.size === 0) {
146
+ vueVersion = 0;
147
+ }
148
+ else if (vueVersionSet.size === 1) {
149
+ vueVersion = vueVersionSet.has(3) ? 3 : 2;
150
+ }
151
+ else {
152
+ const lib2vueVersionMap = libNames.reduce((map, libName, index) => {
153
+ map[libName] = vueVersions[index];
154
+ return map;
155
+ }, {});
156
+ throw new Error(`Libraries' vue versions conflict!
157
+ Vue2 and Vue3 should not be present at the same time!
158
+ detail: ${JSON.stringify(lib2vueVersionMap, null, 2)}`);
159
+ }
109
160
  console.timeEnd(runHandleMaterialTag);
110
161
  // // 获取 generate 需要的构建文件
111
162
  const runGenerateTag = '🚥 buildWebApp-generateProjectFiles';
@@ -132,95 +183,102 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
132
183
  privatelinkConfig,
133
184
  });
134
185
  console.timeEnd(runGenerateTag);
135
- // // 构建 NPM 包
136
- await (0, npm_1.handleNPM)({
137
- appKey,
138
- mainAppData,
139
- subAppDataList,
140
- appBuildDir: h5BuildDir,
141
- dependencies: processedDependencies,
142
- mode,
143
- devTool,
144
- ignoreInstall,
145
- });
146
- // 生成主题文件
147
- await (0, generate_1.generateThemeVarsFile)(mainAppData.themeVars, h5BuildDir);
148
- // 生成 webpack 配置
149
- const webpackConfigPath = await (0, webpack_1.runWebpackCore)({
150
- buildContext,
151
- cals,
152
- appKey,
153
- mainAppData,
154
- subAppDataList,
155
- appBuildDir: h5BuildDir,
156
- assets: jsAssets,
157
- buildTypeList,
158
- mode,
159
- devTool,
160
- publicPath,
161
- domain,
162
- cdnEndpoints,
163
- });
164
- await new Promise((resolve, reject) => {
165
- // 开始编译前清理一下 lowcode 内容
166
- (0, compile_1.startCompile)({
186
+ if (!(0, common_3.buildAsLibByBuildType)(buildTypeList)) {
187
+ // // 构建 NPM 包
188
+ await (0, npm_1.handleNPM)({
189
+ appKey,
190
+ mainAppData,
191
+ subAppDataList,
167
192
  appBuildDir: h5BuildDir,
168
- configPath: webpackConfigPath,
193
+ dependencies: processedDependencies,
194
+ mode,
195
+ devTool,
196
+ ignoreInstall,
197
+ vueVersion,
198
+ });
199
+ // 生成主题文件
200
+ await (0, generate_1.generateThemeVarsFile)(mainAppData.themeVars, h5BuildDir);
201
+ // 生成 webpack 配置
202
+ const webpackConfigPath = await (0, webpack_1.runWebpackCore)({
203
+ buildContext,
204
+ cals,
169
205
  appKey,
170
- webpackMode: mode,
171
- }, function (err, data) {
172
- if (err) {
173
- reject(err);
174
- }
175
- else {
176
- resolve(data);
177
- }
206
+ mainAppData,
207
+ subAppDataList,
208
+ appBuildDir: h5BuildDir,
209
+ assets: jsAssets,
210
+ buildTypeList,
211
+ mode,
212
+ devTool,
213
+ publicPath,
214
+ domain,
215
+ cdnEndpoints,
216
+ vueVersion,
178
217
  });
179
- });
180
- const MAINIFAST_FILENAME = 'weda-manifest.json';
181
- const preHeatUrls = fs_extra_1.default
182
- .readdirSync(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR))
183
- .filter((file) => junk.not(file) && file !== MAINIFAST_FILENAME)
184
- .map((file) => {
185
- if (/LICENSE\.txt$/.test(file) || /\.map$/.test(file)) {
186
- return '';
218
+ if (typeof libNameWithVue === 'string' && !fs_extra_1.default.existsSync(path_1.default.resolve(h5BuildDir, 'node_modules', 'vue'))) {
219
+ fs_extra_1.default.symlinkSync(path_1.default.resolve(h5BuildDir, 'src', 'libraries', libNameWithVue, 'node_modules', 'vue'), path_1.default.resolve(h5BuildDir, 'node_modules', 'vue'));
187
220
  }
188
- try {
189
- const url = new url_1.URL(publicPath);
190
- return `${url.origin}${path_1.default.posix.join(url.pathname, file)}`;
191
- }
192
- catch (e) {
193
- return path_1.default.posix.join(publicPath || '', file);
194
- }
195
- })
196
- .filter((item) => !!item);
197
- // 普通 web 模式,且非hash模式,根据页面生成多份入口
198
- if (!((_f = cals.extra) === null || _f === void 0 ? void 0 : _f.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
199
- preHeatUrls.push(path_1.default.posix.join(basename || ''));
200
- await Promise.all([
201
- ...(cals.items || []).map((page) => {
202
- preHeatUrls.push(path_1.default.posix.join(basename || '', page.id));
203
- preHeatUrls.push(path_1.default.posix.join(basename || '', page.id, '/'));
204
- return fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, page.id, 'index.html'));
205
- }),
206
- ...(subAppCalsList || []).reduce((list, cals) => {
207
- const { rootPath } = cals.extra || {};
208
- const packageName = (0, util_1.normalizePackageName)(rootPath);
209
- if (packageName) {
210
- preHeatUrls.push(path_1.default.posix.join(basename || '', packageName));
211
- preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, '/'));
212
- list.push(fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, packageName, 'index.html')));
213
- (cals.items || []).forEach((page) => {
214
- preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id));
215
- preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id, '/'));
216
- list.push(fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, packageName, page.id, 'index.html')));
217
- });
221
+ await new Promise((resolve, reject) => {
222
+ // 开始编译前清理一下 lowcode 内容
223
+ (0, compile_1.startCompile)({
224
+ appBuildDir: h5BuildDir,
225
+ configPath: webpackConfigPath,
226
+ appKey,
227
+ webpackMode: mode,
228
+ }, function (err, data) {
229
+ if (err) {
230
+ reject(err);
231
+ }
232
+ else {
233
+ resolve(data);
218
234
  }
219
- return list;
220
- }, []),
221
- ]);
235
+ });
236
+ });
237
+ const MAINIFAST_FILENAME = 'weda-manifest.json';
238
+ const preHeatUrls = fs_extra_1.default
239
+ .readdirSync(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR))
240
+ .filter((file) => junk.not(file) && file !== MAINIFAST_FILENAME)
241
+ .map((file) => {
242
+ if (/LICENSE\.txt$/.test(file) || /\.map$/.test(file)) {
243
+ return '';
244
+ }
245
+ try {
246
+ const url = new url_1.URL(publicPath);
247
+ return `${url.origin}${path_1.default.posix.join(url.pathname, file)}`;
248
+ }
249
+ catch (e) {
250
+ return path_1.default.posix.join(publicPath || '', file);
251
+ }
252
+ })
253
+ .filter((item) => !!item);
254
+ // 普通 web 模式,且非hash模式,根据页面生成多份入口
255
+ if (!((_h = cals.extra) === null || _h === void 0 ? void 0 : _h.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
256
+ preHeatUrls.push(path_1.default.posix.join(basename || ''));
257
+ await Promise.all([
258
+ ...(cals.items || []).map((page) => {
259
+ preHeatUrls.push(path_1.default.posix.join(basename || '', page.id));
260
+ preHeatUrls.push(path_1.default.posix.join(basename || '', page.id, '/'));
261
+ return fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, page.id, 'index.html'));
262
+ }),
263
+ ...(subAppCalsList || []).reduce((list, cals) => {
264
+ const { rootPath } = cals.extra || {};
265
+ const packageName = (0, util_1.normalizePackageName)(rootPath);
266
+ if (packageName) {
267
+ preHeatUrls.push(path_1.default.posix.join(basename || '', packageName));
268
+ preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, '/'));
269
+ list.push(fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, packageName, 'index.html')));
270
+ (cals.items || []).forEach((page) => {
271
+ preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id));
272
+ preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id, '/'));
273
+ list.push(fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, packageName, page.id, 'index.html')));
274
+ });
275
+ }
276
+ return list;
277
+ }, []),
278
+ ]);
279
+ }
280
+ await fs_extra_1.default.writeFile(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, MAINIFAST_FILENAME), JSON.stringify({ preHeatUrls }, undefined, 2));
222
281
  }
223
- await fs_extra_1.default.writeFile(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'weda-manifest.json'), JSON.stringify({ preHeatUrls }, undefined, 2));
224
282
  return h5BuildDir;
225
283
  }
226
284
  catch (e) {
@@ -1,5 +1,5 @@
1
1
  import { IMaterialItem, IWebRuntimeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
- export declare function handleNPM({ mainAppData, subAppDataList, dependencies, appKey, appBuildDir, mode, devTool, ignoreInstall, }: {
2
+ export declare function handleNPM({ mainAppData, subAppDataList, dependencies, appKey, appBuildDir, mode, devTool, ignoreInstall, vueVersion, }: {
3
3
  appKey: string;
4
4
  appBuildDir: string;
5
5
  mode: string;
@@ -8,5 +8,6 @@ export declare function handleNPM({ mainAppData, subAppDataList, dependencies, a
8
8
  dependencies: IMaterialItem[];
9
9
  devTool: string;
10
10
  ignoreInstall?: boolean;
11
+ vueVersion?: number;
11
12
  }): Promise<void>;
12
- export declare function generatePackageJSON(dependencies: object | undefined, appBuildDir: string, appKey: string, mode: string, devTool: string): Promise<boolean>;
13
+ export declare function generatePackageJSON(dependencies: object | undefined, appBuildDir: string, appKey: string, mode: string, devTool: string, vueVersion?: number): Promise<boolean>;
@@ -12,7 +12,7 @@ const config_1 = require("../config");
12
12
  const generateFiles_1 = require("../util/generateFiles");
13
13
  const lodash_1 = require("lodash");
14
14
  const util_1 = require("../util");
15
- async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [], appKey, appBuildDir, mode, devTool, ignoreInstall = false, }) {
15
+ async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [], appKey, appBuildDir, mode, devTool, ignoreInstall = false, vueVersion = 0, }) {
16
16
  const allAppDataList = subAppDataList.concat(mainAppData);
17
17
  // 安装 NPM 依赖
18
18
  const deps = {};
@@ -37,7 +37,7 @@ async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [],
37
37
  // Object.assign(deps, comp.npmDependencies);
38
38
  // });
39
39
  // });
40
- const isChange = await generatePackageJSON(deps, appBuildDir, appKey, mode, devTool);
40
+ const isChange = await generatePackageJSON(deps, appBuildDir, appKey, mode, devTool, vueVersion);
41
41
  if (!isChange) {
42
42
  (0, console_1.notice)('package.json dependencies 已经安装,如出现未安装成功或找不到依赖,请重启wa watch');
43
43
  }
@@ -47,7 +47,7 @@ async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [],
47
47
  });
48
48
  }
49
49
  exports.handleNPM = handleNPM;
50
- async function generatePackageJSON(dependencies = {}, appBuildDir, appKey, mode, devTool) {
50
+ async function generatePackageJSON(dependencies = {}, appBuildDir, appKey, mode, devTool, vueVersion = 0) {
51
51
  const templatePath = path_1.default.join(config_1.appTemplateDir, 'package.json');
52
52
  const dstFilePath = path_1.default.join(appBuildDir, 'package.json');
53
53
  const dstTempPath = path_1.default.join(appBuildDir, '.temp', 'package.json');
@@ -57,12 +57,9 @@ async function generatePackageJSON(dependencies = {}, appBuildDir, appKey, mode,
57
57
  canUseVite: (0, util_1.canUseVite)(mode, devTool),
58
58
  appKey,
59
59
  appId: appKey,
60
+ vueVersion: vueVersion === 3 ? '^3' : '^2',
60
61
  }));
61
62
  const packageInfo = await fs_extra_1.default.readJSON(dstTempPath);
62
- // weapps-sdk 要与 builder template 版本一致
63
- // govcloud 包废弃
64
- // dependencies['@govcloud/weapps-sdk'] =
65
- // packageInfo.dependencies['@govcloud/weapps-sdk'];
66
63
  Object.keys(dependencies).forEach((key) => {
67
64
  const version = dependencies[key];
68
65
  if (packageInfo.dependencies[key] !== version) {
@@ -11,6 +11,7 @@ interface IWebpackCoreProps extends BuildAppProps {
11
11
  subAppDataList: IWebRuntimeAppData[];
12
12
  assets: string[];
13
13
  cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
14
+ vueVersion?: number;
14
15
  }
15
- export declare function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, assets, devTool, generateMpType, cdnEndpoints, }: IWebpackCoreProps): Promise<string>;
16
+ export declare function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, assets, devTool, generateMpType, cdnEndpoints, vueVersion, }: IWebpackCoreProps): Promise<string>;
16
17
  export {};
@@ -5,7 +5,7 @@ const common_1 = require("../types/common");
5
5
  const webpack_1 = require("../service/webpack");
6
6
  const generate_1 = require("./generate");
7
7
  const cals_1 = require("@cloudbase/cals");
8
- async function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, }) {
8
+ async function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, vueVersion = 0, }) {
9
9
  var _a;
10
10
  console.time('runWebpackCore');
11
11
  console.time('webpackGenerate');
@@ -18,6 +18,7 @@ async function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList,
18
18
  mode,
19
19
  buildTypeList,
20
20
  assets,
21
+ vueVersion,
21
22
  });
22
23
  console.timeEnd('webpackGenerate');
23
24
  await (0, generate_1.generateHTML)({
@@ -38,14 +39,6 @@ async function runWebpackCore({ buildContext, cals, mainAppData, subAppDataList,
38
39
  cdnEndpoints,
39
40
  publicPath,
40
41
  });
41
- if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
42
- if (mode !== common_1.WebpackModeType.PRODUCTION) {
43
- await (0, webpack_1.generateWebpackWebDevServerFile)({
44
- appBuildDir,
45
- buildTypeList,
46
- });
47
- }
48
- }
49
42
  console.timeEnd('runWebpackCore');
50
43
  return webWebpackConfigPath;
51
44
  }
@@ -82,6 +82,10 @@ export interface IAppCommonBuildContext extends ICommonBuildContext {
82
82
  * 自定义状态页Id
83
83
  */
84
84
  statusPageId?: string;
85
+ /**
86
+ * use official lib npm
87
+ */
88
+ enableOfficialLibNPM?: boolean;
85
89
  }
86
90
  export interface IMpCommonBuildContext extends ICommonBuildContext {
87
91
  /**
@@ -31,7 +31,7 @@ export interface IMpConfig {
31
31
  };
32
32
  }
33
33
  export declare function fixAppJson(appBuildDir: string): Promise<void>;
34
- export declare function generateWebpackWebBuildParamsFile({ appId, allAppDataList, appBuildDir, publicPath, mode, buildTypeList, assets, }: {
34
+ export declare function generateWebpackWebBuildParamsFile({ appId, allAppDataList, appBuildDir, publicPath, mode, buildTypeList, assets, vueVersion, }: {
35
35
  appId: string;
36
36
  allAppDataList: IWebRuntimeAppData[];
37
37
  appBuildDir: string;
@@ -39,6 +39,7 @@ export declare function generateWebpackWebBuildParamsFile({ appId, allAppDataLis
39
39
  mode: WebpackModeType;
40
40
  buildTypeList: BuildType[];
41
41
  assets: string[];
42
+ vueVersion?: number;
42
43
  }): Promise<string>;
43
44
  export interface IGenerateMpJsonConfigFileOpts {
44
45
  appKey?: string;
@@ -49,7 +50,6 @@ export declare function downloadAndWriteTabBarIcon(iconPath: any, pagePath: any,
49
50
  export declare function getMainAppDataByList(allAppDataList: IWebRuntimeAppData[]): IWebRuntimeAppData | undefined;
50
51
  export declare function getHomePageInstance(pageInstanceList: any): any;
51
52
  export declare function getPageName(name: string): string;
52
- export declare function getWebpackWebBuildParams(appId: string, appBuildDir: string, publicPath?: string, mode?: WebpackModeType, buildTypeList?: BuildType[], extraDefine?: {}, assets?: string[]): any;
53
53
  export declare function downloadAndInstallDependencies(dependencies: IMaterialItem[] | undefined, materialsDir: string, installOptions?: IInstallOpts): Promise<void>;
54
54
  export declare function downloadDependencies(targetDir: string, srcZipUrl: string): Promise<void>;
55
55
  /**
@@ -76,9 +76,5 @@ interface IFixNodeModulesMap {
76
76
  '@cloudbase/js-sdk'?: boolean;
77
77
  }
78
78
  export declare function getMaterialNodeModulesPathList(dependencies: IMaterialItem[] | undefined, materialsDir: string, base?: string): string[];
79
- export declare function generateWebpackWebDevServerFile({ appBuildDir, buildTypeList }: {
80
- appBuildDir: any;
81
- buildTypeList: any;
82
- }): Promise<void>;
83
79
  export declare function downloadAssets(targetDir: string, assetUrl: string): Promise<unknown>;
84
80
  export {};
@@ -3,10 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadAssets = exports.generateWebpackWebDevServerFile = exports.getMaterialNodeModulesPathList = exports.installDependencies = exports.downloadDependencies = exports.downloadAndInstallDependencies = exports.getWebpackWebBuildParams = exports.getPageName = exports.getHomePageInstance = exports.getMainAppDataByList = exports.downloadAndWriteTabBarIcon = exports.generateKboneTabBarConfig = exports.generateWebpackWebBuildParamsFile = exports.fixAppJson = exports.OUTPUT_DIR = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
6
+ exports.downloadAssets = exports.getMaterialNodeModulesPathList = exports.installDependencies = exports.downloadDependencies = exports.downloadAndInstallDependencies = exports.getPageName = exports.getHomePageInstance = exports.getMainAppDataByList = exports.downloadAndWriteTabBarIcon = exports.generateKboneTabBarConfig = exports.generateWebpackWebBuildParamsFile = exports.fixAppJson = exports.OUTPUT_DIR = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const lodash_1 = require("lodash");
10
9
  const util_1 = require("../util");
11
10
  const axios_1 = __importDefault(require("axios"));
12
11
  const compressing_1 = __importDefault(require("compressing"));
@@ -39,15 +38,24 @@ async function fixAppJson(appBuildDir) {
39
38
  await fs_extra_1.default.writeFile(appJsonPath, JSON.stringify(appJson, null, 2));
40
39
  }
41
40
  exports.fixAppJson = fixAppJson;
42
- async function generateWebpackWebBuildParamsFile({ appId, allAppDataList, appBuildDir, publicPath, mode, buildTypeList, assets = [], }) {
41
+ async function generateWebpackWebBuildParamsFile({ appId, allAppDataList, appBuildDir, publicPath, mode, buildTypeList, assets = [], vueVersion = 0, }) {
43
42
  let mainAppData = getMainAppDataByList(allAppDataList);
44
- let extraDefine = {
45
- 'process.env.historyType': `"${mainAppData.historyType || types_1.HISTORY_TYPE.BROWSER}"`,
46
- };
47
- const params = getWebpackWebBuildParams(appId, appBuildDir, publicPath, mode, buildTypeList, extraDefine, assets);
48
43
  const webpackConfigPath = path_1.default.resolve(appBuildDir, './webpack/webpack.web.prod.js');
49
- const paramsString = JSON.stringify(params, null, 2);
50
- const webpackConfigContent = `const params = ${paramsString};\nmodule.exports = require('./web.prod.js')(params);`;
44
+ const paramsString = JSON.stringify({
45
+ output: {
46
+ path: exports.OUTPUT_DIR,
47
+ publicPath: buildTypeList.includes(common_1.BuildType.APP) || buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL) ? '' : publicPath,
48
+ },
49
+ definePlugin: {
50
+ 'process.env.historyType': `"${mainAppData.historyType || types_1.HISTORY_TYPE.BROWSER}"`,
51
+ },
52
+ devtool: ['app-nvzcvt10', 'app-msa2ihs9', 'app-PMoFiTuX'].includes(appId)
53
+ ? 'source-map'
54
+ : mode !== common_1.WebpackModeType.PRODUCTION
55
+ ? 'eval'
56
+ : false,
57
+ }, null, 2);
58
+ const webpackConfigContent = `params = ${paramsString};\nmodule.exports = require('./web.prod.js')(params);`;
51
59
  await (0, generateFiles_1.writeFile)(webpackConfigPath, webpackConfigContent);
52
60
  return webpackConfigPath;
53
61
  }
@@ -119,45 +127,6 @@ function getPageName(name) {
119
127
  return `${name}`;
120
128
  }
121
129
  exports.getPageName = getPageName;
122
- function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = common_1.WebpackModeType.NONE, buildTypeList = [common_1.BuildType.WEB], extraDefine = {}, assets = []) {
123
- return {
124
- context: appBuildDir,
125
- mode: mode !== common_1.WebpackModeType.PRODUCTION ? 'development' : mode,
126
- watch: false,
127
- entry: path_1.default.resolve(appBuildDir, 'src/index.jsx'),
128
- output: {
129
- path: path_1.default.resolve(appBuildDir, exports.OUTPUT_DIR),
130
- filename: '[name].[hash].bundle.js',
131
- chunkFilename: '[name].[contenthash].chunk.js',
132
- publicPath: buildTypeList.includes(common_1.BuildType.APP) || buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL) ? '' : publicPath,
133
- pathinfo: false,
134
- // clean: mode === WebpackModeType.PRODUCTION,
135
- },
136
- htmlTemplatePath: path_1.default.resolve(appBuildDir, './index.html'),
137
- externals: {
138
- react: 'window.React',
139
- 'react-dom': 'window.ReactDOM',
140
- mobx: 'window.mobx',
141
- '@cloudbase/js-sdk': 'window.cloudbase',
142
- '@cloudbase/weda-cloud-sdk/dist/h5': 'window.CloudSDK',
143
- '@cloudbase/weda-cloud-sdk': 'window.CloudSDK',
144
- '@cloudbase/weda-client': 'window.WedaClientSDK',
145
- '@zxing/library': 'window.ZXing',
146
- '@cloudbase/lowcode-render': 'window["weda-render"]',
147
- },
148
- resolveModules: [path_1.default.resolve(appBuildDir), 'node_modules'],
149
- definePlugin: {
150
- 'process.env.buildType': `"${buildTypeList[0]}"`,
151
- ...extraDefine,
152
- },
153
- devtool: ['app-nvzcvt10', 'app-msa2ihs9', 'app-PMoFiTuX'].includes(appId)
154
- ? 'source-map'
155
- : mode !== common_1.WebpackModeType.PRODUCTION
156
- ? 'eval'
157
- : false,
158
- };
159
- }
160
- exports.getWebpackWebBuildParams = getWebpackWebBuildParams;
161
130
  async function downloadAndInstallDependencies(dependencies = [], materialsDir, installOptions = {}) {
162
131
  const localPkg = (0, util_1.getCurrentPackageJson)();
163
132
  await Promise.all(dependencies.map(async (item) => {
@@ -368,22 +337,6 @@ function getMaterialNodeModulesPathList(dependencies = [], materialsDir, base) {
368
337
  });
369
338
  }
370
339
  exports.getMaterialNodeModulesPathList = getMaterialNodeModulesPathList;
371
- // 生成devServer 核心依赖
372
- async function generateWebpackWebDevServerFile({ appBuildDir, buildTypeList }) {
373
- const dest = path_1.default.resolve(appBuildDir, `./webpack/devServer.js`);
374
- const template = await fs_extra_1.default.readFile(path_1.default.resolve(config_1.appTemplateDir, './webpack/devServer.js'), {
375
- encoding: 'utf8',
376
- });
377
- const jsContent = (0, lodash_1.template)(template, {
378
- interpolate: /<%=([\s\S]+?)%>/g,
379
- })({
380
- isApp: buildTypeList.includes(common_1.BuildType.APP),
381
- isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
382
- });
383
- await fs_extra_1.default.ensureFile(dest);
384
- await fs_extra_1.default.writeFile(dest, jsContent);
385
- }
386
- exports.generateWebpackWebDevServerFile = generateWebpackWebDevServerFile;
387
340
  // 下载js 文件
388
341
  async function downloadAssets(targetDir, assetUrl) {
389
342
  const isExist = fs_extra_1.default.existsSync(path_1.default.join(targetDir, 'package.json'));
@@ -10,7 +10,6 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
10
10
  const style_1 = require("@cloudbase/lowcode-generator/lib/generator/util/style");
11
11
  const generateFiles_1 = require("./generateFiles");
12
12
  const cals_1 = require("@cloudbase/cals");
13
- const compare_versions_1 = __importDefault(require("compare-versions"));
14
13
  const config_1 = require("../config");
15
14
  const os_1 = __importDefault(require("os"));
16
15
  var common_1 = require("@cloudbase/lowcode-generator/lib/generator/util/common");
@@ -184,7 +183,6 @@ exports.isOfficialComponentLib = isOfficialComponentLib;
184
183
  */
185
184
  function canUseVite(mode, devTool) {
186
185
  return false;
187
- return devTool === 'vite' && mode !== 'production' && (0, compare_versions_1.default)(process.version, '12.0.0') >= 0;
188
186
  }
189
187
  exports.canUseVite = canUseVite;
190
188
  function deepDealComponentSchemaJson(schema, dealFn) {