fix(vite): dev ssr fouc with preprocessors (#1101)

This commit is contained in:
Anthony Fu 2021-10-18 15:54:20 +08:00 committed by GitHub
parent b3ff8eeaed
commit 39ed77e229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import * as vite from 'vite'
import consola from 'consola' import consola from 'consola'
import vitePlugin from '@vitejs/plugin-vue' import vitePlugin from '@vitejs/plugin-vue'
import viteJsxPlugin from '@vitejs/plugin-vue-jsx' import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import type { Connect } from 'vite'
import { cacheDirPlugin } from './plugins/cache-dir' import { cacheDirPlugin } from './plugins/cache-dir'
import { replace } from './plugins/replace' import { replace } from './plugins/replace'
@ -49,7 +50,7 @@ export async function buildClient (ctx: ViteBuildContext) {
const viteServer = await vite.createServer(clientConfig) const viteServer = await vite.createServer(clientConfig)
await ctx.nuxt.callHook('vite:serverCreated', viteServer) await ctx.nuxt.callHook('vite:serverCreated', viteServer)
const viteMiddleware = (req, res, next) => { const viteMiddleware: Connect.NextHandleFunction = (req, res, next) => {
// Workaround: vite devmiddleware modifies req.url // Workaround: vite devmiddleware modifies req.url
const originalURL = req.url const originalURL = req.url
viteServer.middlewares.handle(req, res, (err) => { viteServer.middlewares.handle(req, res, (err) => {

View File

@ -15,7 +15,7 @@ export function uniq<T> (arr: T[]): T[] {
return Array.from(new Set(arr)) return Array.from(new Set(arr))
} }
const IS_CSS_RE = /\.css(\?[^.]+)?$/ const IS_CSS_RE = /\.(?:css|scss|sass|postcss|less|stylus|styl)(\?[^.]+)?$/
export function isCSS (file: string) { export function isCSS (file: string) {
return IS_CSS_RE.test(file) return IS_CSS_RE.test(file)