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

fix(h5): tree shaking edge case

上级 1fe62fe7
......@@ -147,7 +147,11 @@ export function uniViteInjectPlugin(options: InjectOptions): Plugin {
if (reassignments.has(hash)) {
return false
}
if (parent && isAssignmentExpression(parent)) {
if (
parent &&
isAssignmentExpression(parent) &&
parent.left === node
) {
reassignments.add(hash)
return false
}
......
import path from 'path'
import debug from 'debug'
import type { Plugin } from 'vite'
import { normalizePath, parseVueRequest } from '@dcloudio/uni-cli-shared'
import type { Plugin, ResolvedConfig } from 'vite'
import {
normalizePath,
parseVueRequest,
withSourcemap,
} from '@dcloudio/uni-cli-shared'
const debugSetup = debug('vite:uni:setup')
export function uniSetupPlugin(): Plugin {
let appVuePath: string
let resolvedConfig: ResolvedConfig
return {
name: 'vite:uni-setup',
configResolved() {
configResolved(config) {
resolvedConfig = config
appVuePath = normalizePath(
path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')
)
......@@ -18,10 +24,14 @@ export function uniSetupPlugin(): Plugin {
const { filename, query } = parseVueRequest(id)
if (filename === appVuePath && !query.vue) {
debugSetup(filename)
return (
code +
`;import { setupApp } from '@dcloudio/uni-h5';setupApp(_sfc_main);`
)
return {
code:
code +
`;import { setupApp } from '@dcloudio/uni-h5';setupApp(_sfc_main);`,
map: withSourcemap(resolvedConfig)
? this.getCombinedSourcemap()
: null,
}
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册