69 lines
2.8 KiB
JavaScript
69 lines
2.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createBuild = void 0;
|
|
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
const shared_1 = require("@vue/shared");
|
|
function createBuild(options, config) {
|
|
(0, uni_cli_shared_1.initEasycomsOnce)(options.inputDir, {
|
|
dirs: (0, uni_cli_shared_1.resolveComponentsLibDirs)(),
|
|
platform: process.env.UNI_PLATFORM,
|
|
isX: process.env.UNI_APP_X === 'true',
|
|
});
|
|
const rollupOutputOption = config.build?.rollupOptions?.output;
|
|
const sourcemap = process.env.UNI_APP_SOURCEMAP === 'true'
|
|
? 'hidden'
|
|
: config.build?.sourcemap;
|
|
/**
|
|
* arkts编译器处理字符串模板内使用逗号操作符时有问题,禁用 reduce_vars 减少产出此类代码
|
|
* 如下代码在 arkts 内编译报错,Error Message: Unexpected token, expected '}'.
|
|
* function test () {
|
|
* return 0
|
|
* }
|
|
* let n: number = 0
|
|
* console.log(`${n = test(), n === 0 ? 0 : 1}px`)
|
|
*/
|
|
const isHarmonyArkTs = process.env.UNI_UTS_PLATFORM === 'app-harmony' &&
|
|
process.env.UNI_APP_X_HARMONY_SCRIPT_ENGINE !== 'jsvm';
|
|
return {
|
|
sourcemap,
|
|
cssTarget: uni_cli_shared_1.cssTarget,
|
|
chunkSizeWarningLimit: 100000000,
|
|
minify: config.build && (0, shared_1.hasOwn)(config.build, 'minify')
|
|
? config.build.minify
|
|
: process.env.NODE_ENV === 'production'
|
|
? 'terser'
|
|
: false,
|
|
terserOptions: process.env.NODE_ENV !== 'production'
|
|
? { compress: { drop_console: false, reduce_vars: !isHarmonyArkTs } }
|
|
: isHarmonyArkTs
|
|
? { compress: { reduce_vars: false } }
|
|
: undefined,
|
|
rollupOptions: {
|
|
onwarn(warning, warn) {
|
|
if (warning.code === 'EMPTY_BUNDLE') {
|
|
// 忽略空包警告,通常是条件编译之类导致的
|
|
// Generated an empty chunk:
|
|
return;
|
|
}
|
|
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
|
|
const { message } = warning;
|
|
// ignore
|
|
if (message.includes('"vue"') ||
|
|
message.includes('"resolveComponent"') ||
|
|
message.includes('"@dcloudio/uni-h5"')) {
|
|
return;
|
|
}
|
|
}
|
|
warn(warning);
|
|
},
|
|
output: {
|
|
sourcemapExcludeSources: !(0, shared_1.isArray)(rollupOutputOption) &&
|
|
rollupOutputOption?.sourcemapExcludeSources === false
|
|
? false
|
|
: process.env.UNI_APP_SOURCEMAP === 'true',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
exports.createBuild = createBuild;
|