更新
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
import type { ConfigEnv, UserConfig } from 'vite';
|
||||
export declare function buildOptions({ appService, renderer, }: {
|
||||
renderer: 'native' | undefined;
|
||||
appService: boolean;
|
||||
}, userConfig: UserConfig, _: ConfigEnv): UserConfig['build'];
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.buildOptions = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const utils_1 = require("../utils");
|
||||
function buildOptions({ appService, renderer, }, userConfig, _) {
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const outputDir = process.env.UNI_OUTPUT_DIR;
|
||||
// 开始编译时,清空输出目录
|
||||
function emptyNVueDir() {
|
||||
const nvueOutputDir = (0, utils_1.nvueOutDir)();
|
||||
if (fs_1.default.existsSync(nvueOutputDir)) {
|
||||
(0, uni_cli_shared_1.emptyDir)(nvueOutputDir);
|
||||
}
|
||||
}
|
||||
function emptyOutDir() {
|
||||
if (fs_1.default.existsSync(outputDir)) {
|
||||
(0, uni_cli_shared_1.emptyDir)(outputDir);
|
||||
}
|
||||
}
|
||||
if (renderer === 'native') {
|
||||
if (appService) {
|
||||
// 仅编译 main.js+App.vue 的时候才清空
|
||||
emptyNVueDir();
|
||||
emptyOutDir();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((0, uni_cli_shared_1.isInHybridNVue)(userConfig)) {
|
||||
emptyNVueDir();
|
||||
}
|
||||
else {
|
||||
emptyOutDir();
|
||||
}
|
||||
}
|
||||
const sourcemap = process.env.SOURCEMAP === 'true'
|
||||
? 'hidden'
|
||||
: userConfig.build?.sourcemap
|
||||
? 'inline'
|
||||
: false;
|
||||
return {
|
||||
// App 端目前仅提供 inline
|
||||
sourcemap,
|
||||
emptyOutDir: false, // 不清空输出目录,否则会影响 webpack 的输出
|
||||
assetsInlineLimit: 0,
|
||||
rollupOptions: {
|
||||
input: (0, uni_cli_shared_1.resolveMainPathOnce)(inputDir),
|
||||
output: {
|
||||
sourcemapPathTransform(relativeSourcePath, sourcemapPath) {
|
||||
const sourcePath = (0, uni_cli_shared_1.normalizePath)(path_1.default.relative(inputDir, path_1.default.resolve(path_1.default.dirname(sourcemapPath), relativeSourcePath)));
|
||||
if (sourcePath.startsWith('..')) {
|
||||
return '';
|
||||
}
|
||||
return 'uni-app:///' + sourcePath;
|
||||
},
|
||||
manualChunks: {},
|
||||
inlineDynamicImports: false,
|
||||
chunkFileNames(chunk) {
|
||||
if (chunk.isDynamicEntry && chunk.facadeModuleId) {
|
||||
const filepath = path_1.default.relative(inputDir, chunk.facadeModuleId);
|
||||
return (0, uni_cli_shared_1.normalizePath)(filepath.replace(path_1.default.extname(filepath), '.js'));
|
||||
}
|
||||
return '[name].js';
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.buildOptions = buildOptions;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { Plugin, ResolvedConfig } from 'vite';
|
||||
export declare function createConfigResolved({ createCssPostPlugin, }: {
|
||||
createCssPostPlugin: (config: ResolvedConfig) => Plugin;
|
||||
}): Plugin['configResolved'];
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createConfigResolved = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
function createConfigResolved({ createCssPostPlugin, }) {
|
||||
return (config) => {
|
||||
(0, uni_cli_shared_1.injectCssPlugin)(config, process.env.UNI_COMPILE_TARGET === 'uni_modules'
|
||||
? {
|
||||
createUrlReplacer: uni_cli_shared_1.createEncryptCssUrlReplacer,
|
||||
}
|
||||
: {});
|
||||
(0, uni_cli_shared_1.injectCssPostPlugin)(config, createCssPostPlugin(config));
|
||||
// 强制不inline
|
||||
config.build.assetsInlineLimit = 0;
|
||||
(0, uni_cli_shared_1.injectAssetPlugin)(config);
|
||||
};
|
||||
}
|
||||
exports.createConfigResolved = createConfigResolved;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { type UniVitePlugin } from '@dcloudio/uni-cli-shared';
|
||||
export declare function uniAppPlugin({ renderer, appService, }?: {
|
||||
renderer?: 'native';
|
||||
appService: boolean;
|
||||
}): UniVitePlugin;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniAppPlugin = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const uni_1 = require("./uni");
|
||||
const build_1 = require("./build");
|
||||
function uniAppPlugin({ renderer, appService, } = {
|
||||
appService: false,
|
||||
}) {
|
||||
return {
|
||||
name: 'uni:app',
|
||||
uni: (0, uni_1.uniOptions)(),
|
||||
config(config, env) {
|
||||
return {
|
||||
base: '/', // app 平台强制 base
|
||||
build: (0, build_1.buildOptions)({ renderer, appService }, config, env),
|
||||
optimizeDeps: {
|
||||
noDiscovery: true,
|
||||
include: [],
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
// vue-i18n 默认会启用 new Function 来构造翻译函数,导致在 Android 上可能报`TypeError: no access` 错误
|
||||
// 故:启用 runtime 模式,内部定制了简易的 compileToFunction
|
||||
'vue-i18n': (0, uni_cli_shared_1.resolveVueI18nRuntime)(),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniAppPlugin = uniAppPlugin;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { type UniVitePlugin } from '@dcloudio/uni-cli-shared';
|
||||
export declare function uniOptions(compilerType?: "vue" | "nvue"): UniVitePlugin['uni'];
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniOptions = void 0;
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const uni_i18n_1 = require("@dcloudio/uni-i18n");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const nvue_1 = require("../../nvue");
|
||||
const plugin_1 = require("../../nvue/plugin");
|
||||
const transformWxsProps_1 = require("./transforms/transformWxsProps");
|
||||
function isAppNVueNativeTag(tag) {
|
||||
return (0, uni_cli_shared_1.matchUTSComponent)(tag) || (0, uni_shared_1.isAppNVueNativeTag)(tag);
|
||||
}
|
||||
function uniOptions(compilerType = process.env.UNI_COMPILER) {
|
||||
const isNVueCompiler = compilerType === 'nvue';
|
||||
return {
|
||||
copyOptions() {
|
||||
const platform = process.env.UNI_PLATFORM;
|
||||
const inputDir = process.env.UNI_INPUT_DIR;
|
||||
const outputDir = process.env.UNI_OUTPUT_DIR;
|
||||
const targets = [];
|
||||
// 自动化测试时,不启用隐私政策
|
||||
if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
|
||||
targets.push({
|
||||
src: 'androidPrivacy.json',
|
||||
dest: outputDir,
|
||||
transform(source) {
|
||||
const options = (0, uni_cli_shared_1.initI18nOptions)(platform, inputDir, false, true);
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
return (0, uni_i18n_1.compileI18nJsonStr)(source.toString(), options);
|
||||
},
|
||||
});
|
||||
const debugFilename = '__nvue_debug__';
|
||||
if (fs_extra_1.default.existsSync(path_1.default.resolve(inputDir, debugFilename))) {
|
||||
targets.push({
|
||||
src: debugFilename,
|
||||
dest: outputDir,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
assets: ['hybrid/html/**/*', 'uni_modules/*/hybrid/html/**/*'],
|
||||
targets,
|
||||
};
|
||||
},
|
||||
compilerOptions: {
|
||||
isNativeTag: isNVueCompiler ? isAppNVueNativeTag : uni_shared_1.isAppNativeTag,
|
||||
isVoidTag: uni_shared_1.isAppVoidTag,
|
||||
nodeTransforms: [
|
||||
...(isNVueCompiler ? (0, nvue_1.initNVueNodeTransforms)() : [transformWxsProps_1.transformWxsProps]),
|
||||
uni_cli_shared_1.transformTapToClick,
|
||||
uni_cli_shared_1.transformMatchMedia,
|
||||
uni_cli_shared_1.transformPageHead,
|
||||
],
|
||||
directiveTransforms: {
|
||||
...(isNVueCompiler ? (0, plugin_1.initNVueDirectiveTransforms)() : {}),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniOptions = uniOptions;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare const WXS_PROP: unique symbol;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WXS_PROP = void 0;
|
||||
const compiler_core_1 = require("@vue/compiler-core");
|
||||
exports.WXS_PROP = Symbol(`wxsProp`);
|
||||
(0, compiler_core_1.registerRuntimeHelpers)({
|
||||
[exports.WXS_PROP]: 'wp',
|
||||
});
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import { type NodeTransform } from '@vue/compiler-core';
|
||||
export declare const transformWxsProps: NodeTransform;
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformWxsProps = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const compiler_core_1 = require("@vue/compiler-core");
|
||||
const runtimeHelpers_1 = require("./runtimeHelpers");
|
||||
const transformWxsProps = (node, context) => {
|
||||
if (!(0, uni_cli_shared_1.isElementNode)(node)) {
|
||||
return;
|
||||
}
|
||||
node.props.forEach((prop) => {
|
||||
if ((0, uni_cli_shared_1.isDirectiveNode)(prop) && prop.arg && (0, uni_cli_shared_1.isSimpleExpressionNode)(prop.arg)) {
|
||||
const { content } = prop.arg;
|
||||
if (content.startsWith(uni_shared_1.ATTR_CHANGE_PREFIX)) {
|
||||
const propName = content.substring(uni_shared_1.ATTR_CHANGE_PREFIX.length);
|
||||
const wxsProp = (0, compiler_core_1.findProp)(node, propName, true);
|
||||
if (wxsProp && (0, uni_cli_shared_1.isDirectiveNode)(wxsProp) && wxsProp.exp) {
|
||||
wxsProp.exp = (0, compiler_core_1.createCompoundExpression)([
|
||||
context.helperString(runtimeHelpers_1.WXS_PROP),
|
||||
'(',
|
||||
wxsProp.exp,
|
||||
')',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
exports.transformWxsProps = transformWxsProps;
|
||||
Reference in New Issue
Block a user