Skip to content

Commit 01bdac9

Browse files
oliverzy周毓杰haoqunjiang
authored
fix(plugin-vue): respect __VUE_PROD_DEVTOOLS__ setting (#4984)
Co-authored-by: 周毓杰 <[email protected]> Co-authored-by: Haoqun Jiang <[email protected]>
1 parent 187da51 commit 01bdac9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/plugin-vue/src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface ResolvedOptions extends Options {
6464
root: string
6565
sourceMap: boolean
6666
devServer?: ViteDevServer
67+
devToolsEnabled?: boolean
6768
}
6869

6970
export default function vuePlugin(rawOptions: Options = {}): Plugin {
@@ -97,7 +98,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
9798
customElement,
9899
reactivityTransform,
99100
root: process.cwd(),
100-
sourceMap: true
101+
sourceMap: true,
102+
devToolsEnabled: process.env.NODE_ENV !== 'production'
101103
}
102104

103105
// Temporal handling for 2.7 breaking change
@@ -135,7 +137,9 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
135137
...options,
136138
root: config.root,
137139
sourceMap: config.command === 'build' ? !!config.build.sourcemap : true,
138-
isProduction: config.isProduction
140+
isProduction: config.isProduction,
141+
devToolsEnabled:
142+
!!config.define!.__VUE_PROD_DEVTOOLS__ || !config.isProduction
139143
}
140144
},
141145

packages/plugin-vue/src/main.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function transformMain(
2727
ssr: boolean,
2828
asCustomElement: boolean
2929
) {
30-
const { devServer, isProduction } = options
30+
const { devServer, isProduction, devToolsEnabled } = options
3131

3232
// prev descriptor is only set and used for hmr
3333
const prevDescriptor = getPrevDescriptor(filename)
@@ -102,9 +102,12 @@ export async function transformMain(
102102
if (hasScoped) {
103103
attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)])
104104
}
105-
if (devServer && !isProduction) {
105+
if (devToolsEnabled || (devServer && !isProduction)) {
106106
// expose filename during serve for devtools to pickup
107-
attachedProps.push([`__file`, JSON.stringify(filename)])
107+
attachedProps.push([
108+
`__file`,
109+
JSON.stringify(isProduction ? path.basename(filename) : filename)
110+
])
108111
}
109112

110113
// HMR

0 commit comments

Comments
 (0)