diff --git a/packages/uni-cli-shared/src/vue/parse.ts b/packages/uni-cli-shared/src/vue/parse.ts index 7c8bd9ef270d2cd265f4febd2af68e894a6f9c38..f72b3679fc90d1e7debe589da354618695dada1c 100644 --- a/packages/uni-cli-shared/src/vue/parse.ts +++ b/packages/uni-cli-shared/src/vue/parse.ts @@ -13,7 +13,7 @@ const BLOCK_RE = /<\/block>/ const WXS_LANG_RE = /lang=["|'](renderjs|wxs)["|']/ const WXS_ATTRS = ['wxs', 'renderjs'] -export function parseVueCode(code: string) { +export function parseVueCode(code: string, isNVue = false) { const hasBlock = BLOCK_RE.test(code) const hasWxs = WXS_LANG_RE.test(code) if (!hasBlock && !hasWxs) { @@ -27,7 +27,7 @@ export function parseVueCode(code: string) { // 重新解析新的 code ast = parseVue(code, errors) } - if (hasWxs) { + if (!isNVue && hasWxs) { const wxsNodes = parseWxsNodes(ast) code = parseWxsCode(wxsNodes, code) // add watch diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts b/packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts index 19d684bfc8b0a23ee05eada31a6bef9c9f785eda..ded5aab532ae761dd45fc33a0dea8e8a8bbc825f 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts @@ -11,8 +11,12 @@ import { } from '@dcloudio/uni-cli-shared' export function uniPreVuePlugin(): Plugin { + let isNVue = false return { name: 'uni:pre-vue', + config(config) { + isNVue = (config as any).nvue + }, async transform(code, id) { const { filename, query } = parseVueRequest(id) if (query.vue) { @@ -26,7 +30,7 @@ export function uniPreVuePlugin(): Plugin { removeExt(normalizeMiniProgramFilename(id, process.env.UNI_INPUT_DIR)) ) return { - code: parseVueCode(code).code, // 暂不提供sourcemap,意义不大 + code: parseVueCode(code, isNVue).code, // 暂不提供sourcemap,意义不大 map: null, } },