Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/core/src/node/plugins/__tests__/injection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { resolveConfig } from 'vite'
import { describe, expect, it } from 'vitest'
import { DevToolsInjection } from '../injection'

describe('devToolsInjection', () => {
it('defines Vue feature flags for non-Vue hosts', async () => {
const config = await resolveConfig({
configFile: false,
plugins: [DevToolsInjection()],
}, 'serve')

expect(config.define).toMatchObject({
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
})
})

it('preserves Vue feature flags defined by the host', async () => {
const config = await resolveConfig({
configFile: false,
define: {
__VUE_OPTIONS_API__: 'false',
__VUE_PROD_DEVTOOLS__: 'true',
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true',
},
plugins: [DevToolsInjection()],
}, 'serve')

expect(config.define).toMatchObject({
__VUE_OPTIONS_API__: 'false',
__VUE_PROD_DEVTOOLS__: 'true',
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true',
})
})
})
Comment thread
webfansplz marked this conversation as resolved.
9 changes: 9 additions & 0 deletions packages/core/src/node/plugins/injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export function DevToolsInjection(options: DevToolsInjectionOptions = {}): Plugi
apply(_config, env) {
return env.command === 'serve' && !env.isSsrBuild
},
config(config) {
return {
define: {
__VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true,
__VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: config.define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ ?? false,
},
}
},
configResolved(config) {
root = config.root
},
Expand Down
Loading