mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(vite): add additional before skipping vite transform (#10120)
This commit is contained in:
parent
5d069a93ce
commit
1e8da22893
@ -130,11 +130,17 @@ export async function buildClient (ctx: ViteBuildContext) {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
const viteMiddleware = defineEventHandler(async (event) => {
|
||||
// Workaround: vite devmiddleware modifies req.url
|
||||
const originalURL = event.node.req.url!
|
||||
// @ts-expect-error _skip_transform is a private property
|
||||
event.node.req._skip_transform = !originalURL.startsWith(clientConfig.base!)
|
||||
|
||||
const viteRoutes = viteServer.middlewares.stack.map(m => m.route).filter(r => r.length > 1)
|
||||
if (!originalURL.startsWith(clientConfig.base!) && !viteRoutes.some(route => originalURL.startsWith(route))) {
|
||||
// @ts-expect-error _skip_transform is a private property
|
||||
event.node.req._skip_transform = true
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
viteServer.middlewares.handle(event.node.req, event.node.res, (err: Error) => {
|
||||
event.node.req.url = originalURL
|
||||
|
@ -894,6 +894,16 @@ describe('component islands', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe.runIf(process.env.NUXT_TEST_DEV && !process.env.TEST_WITH_WEBPACK)('vite plugins', () => {
|
||||
it('does not override vite plugins', async () => {
|
||||
expect(await $fetch('/vite-plugin-without-path')).toBe('vite-plugin without path')
|
||||
expect(await $fetch('/__nuxt-test')).toBe('vite-plugin with __nuxt prefix')
|
||||
})
|
||||
it('does not allow direct access to nuxt source folder', async () => {
|
||||
expect(await $fetch('/app.config')).toContain('404')
|
||||
})
|
||||
})
|
||||
|
||||
describe.skipIf(process.env.NUXT_TEST_DEV || isWindows)('payload rendering', () => {
|
||||
it('renders a payload', async () => {
|
||||
const payload = await $fetch('/random/a/_payload.js', { responseType: 'text' })
|
||||
|
22
test/fixtures/basic/nuxt.config.ts
vendored
22
test/fixtures/basic/nuxt.config.ts
vendored
@ -100,6 +100,28 @@ export default defineNuxtConfig({
|
||||
export: 'namedExport',
|
||||
filePath: '~/other-components-folder/named-export'
|
||||
})
|
||||
},
|
||||
'vite:extendConfig' (config) {
|
||||
config.plugins!.push({
|
||||
name: 'nuxt:server',
|
||||
configureServer (server) {
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url === '/vite-plugin-without-path') {
|
||||
res.end('vite-plugin without path')
|
||||
return
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url === '/__nuxt-test') {
|
||||
res.end('vite-plugin with __nuxt prefix')
|
||||
return
|
||||
}
|
||||
next()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
experimental: {
|
||||
|
Loading…
Reference in New Issue
Block a user