Skip to content

Commit

Permalink
fix(plugin-vue): respect __VUE_PROD_DEVTOOLS__ setting (#4984)
Browse files Browse the repository at this point in the history
Co-authored-by: 周毓杰 <xiake@xiaohongshu.com>
Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
  • Loading branch information
3 people authored Mar 24, 2022
1 parent 187da51 commit 01bdac9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface ResolvedOptions extends Options {
root: string
sourceMap: boolean
devServer?: ViteDevServer
devToolsEnabled?: boolean
}

export default function vuePlugin(rawOptions: Options = {}): Plugin {
Expand Down Expand Up @@ -97,7 +98,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
customElement,
reactivityTransform,
root: process.cwd(),
sourceMap: true
sourceMap: true,
devToolsEnabled: process.env.NODE_ENV !== 'production'
}

// Temporal handling for 2.7 breaking change
Expand Down Expand Up @@ -135,7 +137,9 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
...options,
root: config.root,
sourceMap: config.command === 'build' ? !!config.build.sourcemap : true,
isProduction: config.isProduction
isProduction: config.isProduction,
devToolsEnabled:
!!config.define!.__VUE_PROD_DEVTOOLS__ || !config.isProduction
}
},

Expand Down
9 changes: 6 additions & 3 deletions packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function transformMain(
ssr: boolean,
asCustomElement: boolean
) {
const { devServer, isProduction } = options
const { devServer, isProduction, devToolsEnabled } = options

// prev descriptor is only set and used for hmr
const prevDescriptor = getPrevDescriptor(filename)
Expand Down Expand Up @@ -102,9 +102,12 @@ export async function transformMain(
if (hasScoped) {
attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)])
}
if (devServer && !isProduction) {
if (devToolsEnabled || (devServer && !isProduction)) {
// expose filename during serve for devtools to pickup
attachedProps.push([`__file`, JSON.stringify(filename)])
attachedProps.push([
`__file`,
JSON.stringify(isProduction ? path.basename(filename) : filename)
])
}

// HMR
Expand Down

0 comments on commit 01bdac9

Please sign in to comment.