Skip to content
Merged
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
9 changes: 9 additions & 0 deletions packages/vite/src/node/__tests__/plugins/define.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ describe('definePlugin (SSR dev)', () => {
).toBe(undefined)
})

test('replaces define keys containing `$`', async () => {
const transform = await createJsDefinePluginTransform({
$FOO: JSON.stringify('bar'),
})
expect(await transform('export const x = $FOO;')).toBe(
'export const x = "bar";\n',
)
})

test('replace import.meta.env when it is a invalid json', async () => {
const transform = await createJsDefinePluginTransform({
'import.meta.env.LEGACY': '__VITE_IS_LEGACY__',
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isHTMLRequest } from './html'

const nonJsRe = /\.json(?:$|\?)/
const isNonJsRequest = (request: string): boolean => nonJsRe.test(request)
const escapedDotRE = /(?<!\\)\\./g
const escapedDotRE = /(?<!\\)\\\./g

export function definePlugin(config: ResolvedConfig): Plugin {
const isBuild = config.command === 'build'
Expand Down
Loading