提交 fae19bef 编写于 作者: fxy060608's avatar fxy060608

feat(uni_modules): support disabled exports

上级 50a9ff71
......@@ -274,6 +274,9 @@ declare namespace UniNamespace {
[name: string]: string
}
}
uni_modules?: {
exports?: boolean
}
condition?: {
current?: number
list?: {
......
......@@ -6,7 +6,11 @@ import { isArray, isPlainObject, isString } from '@vue/shared'
import { UNI_MODULES_EXPORTS } from '../../constants'
import { parseJson } from '../../json'
export function uniModulesExportsPlugin(): Plugin {
export function uniModulesExportsPlugin({
enable,
}: {
enable: boolean
}): Plugin {
return {
name: 'uni:modules:exports',
resolveId(id) {
......@@ -18,6 +22,10 @@ export function uniModulesExportsPlugin(): Plugin {
if (id !== UNI_MODULES_EXPORTS) {
return
}
// 未启用
if (!enable) {
return ''
}
const uniModulesDir = path.resolve(
process.env.UNI_INPUT_DIR,
'uni_modules'
......
......@@ -11,6 +11,7 @@ import {
CopyOptions,
initModuleAlias,
initPreContext,
parsePagesJsonOnce,
resolveSourceMapPath,
uniModulesExportsPlugin,
} from '@dcloudio/uni-cli-shared'
......@@ -86,7 +87,17 @@ export default function uniPlugin(
initPreContext(options.platform, process.env.UNI_CUSTOM_CONTEXT)
const plugins: Plugin[] = [uniModulesExportsPlugin()]
const pagesJson = parsePagesJsonOnce(
process.env.UNI_INPUT_DIR,
process.env.UNI_PLATFORM
)
const plugins: Plugin[] = [
uniModulesExportsPlugin({
enable: pagesJson.uni_modules?.exports === false ? false : true,
}),
]
// 仅限 h5
if (options.viteLegacyOptions && options.platform === 'h5') {
plugins.push(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册