From 149eedef962d7b8c61a715bfff6cef47f43a6241 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 16 Oct 2021 03:38:26 +0800 Subject: [PATCH 1/2] fix(vite): dev ssr fouc with preprocessors --- examples/with-scss/app.vue | 17 ++++++++++++++++ examples/with-scss/nuxt.config.ts | 4 ++++ examples/with-scss/package.json | 14 ++++++++++++++ packages/vite/src/client.ts | 3 ++- packages/vite/src/utils.ts | 2 +- yarn.lock | 32 ++++++++++++++++++++++++++++++- 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 examples/with-scss/app.vue create mode 100644 examples/with-scss/nuxt.config.ts create mode 100644 examples/with-scss/package.json diff --git a/examples/with-scss/app.vue b/examples/with-scss/app.vue new file mode 100644 index 00000000000..49c91c14f63 --- /dev/null +++ b/examples/with-scss/app.vue @@ -0,0 +1,17 @@ + + + diff --git a/examples/with-scss/nuxt.config.ts b/examples/with-scss/nuxt.config.ts new file mode 100644 index 00000000000..a3e4d68096a --- /dev/null +++ b/examples/with-scss/nuxt.config.ts @@ -0,0 +1,4 @@ +import { defineNuxtConfig } from 'nuxt3' + +export default defineNuxtConfig({ +}) diff --git a/examples/with-scss/package.json b/examples/with-scss/package.json new file mode 100644 index 00000000000..3f868cc9af5 --- /dev/null +++ b/examples/with-scss/package.json @@ -0,0 +1,14 @@ +{ + "name": "example-with-scss", + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "start": "node .output/server/index.mjs" + }, + "devDependencies": { + "@types/sass": "^1", + "nuxt3": "latest", + "sass": "^1.42.1" + } +} diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index fd12ab48d8f..c21c47cb4db 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -3,6 +3,7 @@ import * as vite from 'vite' import consola from 'consola' import vitePlugin from '@vitejs/plugin-vue' import viteJsxPlugin from '@vitejs/plugin-vue-jsx' +import type { Connect } from 'vite' import { cacheDirPlugin } from './plugins/cache-dir' import { replace } from './plugins/replace' @@ -49,7 +50,7 @@ export async function buildClient (ctx: ViteBuildContext) { const viteServer = await vite.createServer(clientConfig) 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 const originalURL = req.url viteServer.middlewares.handle(req, res, (err) => { diff --git a/packages/vite/src/utils.ts b/packages/vite/src/utils.ts index 5466159941d..015e0efe317 100644 --- a/packages/vite/src/utils.ts +++ b/packages/vite/src/utils.ts @@ -15,7 +15,7 @@ export function uniq (arr: T[]): T[] { 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) { return IS_CSS_RE.test(file) diff --git a/yarn.lock b/yarn.lock index df12fbe214f..5748c366cd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3566,6 +3566,15 @@ __metadata: languageName: node linkType: hard +"@types/sass@npm:^1": + version: 1.16.1 + resolution: "@types/sass@npm:1.16.1" + dependencies: + "@types/node": "*" + checksum: 3f86d2eaf4988a2775fc0fc164d35e73ce82d71228191da7b11d97ad5e8ac129f1c5f798307e31482f8cfebab758bd3b24e731860bed81afe5a1bbe13fa2b2df + languageName: node + linkType: hard + "@types/semver@npm:^7": version: 7.3.8 resolution: "@types/semver@npm:7.3.8" @@ -6465,7 +6474,7 @@ __metadata: languageName: node linkType: hard -"chokidar@npm:3.5.2, chokidar@npm:^3.4.1, chokidar@npm:^3.5.1, chokidar@npm:^3.5.2": +"chokidar@npm:3.5.2, chokidar@npm:>=3.0.0 <4.0.0, chokidar@npm:^3.4.1, chokidar@npm:^3.5.1, chokidar@npm:^3.5.2": version: 3.5.2 resolution: "chokidar@npm:3.5.2" dependencies: @@ -9273,6 +9282,16 @@ __metadata: languageName: unknown linkType: soft +"example-with-scss@workspace:examples/with-scss": + version: 0.0.0-use.local + resolution: "example-with-scss@workspace:examples/with-scss" + dependencies: + "@types/sass": ^1 + nuxt3: latest + sass: ^1.42.1 + languageName: unknown + linkType: soft + "example-with-wasm@workspace:examples/with-wasm": version: 0.0.0-use.local resolution: "example-with-wasm@workspace:examples/with-wasm" @@ -16980,6 +16999,17 @@ fsevents@~2.3.2: languageName: node linkType: hard +"sass@npm:^1.42.1": + version: 1.42.1 + resolution: "sass@npm:1.42.1" + dependencies: + chokidar: ">=3.0.0 <4.0.0" + bin: + sass: sass.js + checksum: 467817475b23a3da3aac2f5e401f3b3d9431845b31ff1bc6269d4677852b4e1445e50d6ed1a8daffa4a76398cff6c531670171823466137ed8c2721c17983973 + languageName: node + linkType: hard + "sax@npm:^1.2.4, sax@npm:~1.2.4": version: 1.2.4 resolution: "sax@npm:1.2.4" From 7c1cd0296db29846cb4f586e35f3307ef54491a1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 16 Oct 2021 03:41:06 +0800 Subject: [PATCH 2/2] chore: remove example --- examples/with-scss/app.vue | 17 ---------------- examples/with-scss/nuxt.config.ts | 4 ---- examples/with-scss/package.json | 14 -------------- yarn.lock | 32 +------------------------------ 4 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 examples/with-scss/app.vue delete mode 100644 examples/with-scss/nuxt.config.ts delete mode 100644 examples/with-scss/package.json diff --git a/examples/with-scss/app.vue b/examples/with-scss/app.vue deleted file mode 100644 index 49c91c14f63..00000000000 --- a/examples/with-scss/app.vue +++ /dev/null @@ -1,17 +0,0 @@ - - - diff --git a/examples/with-scss/nuxt.config.ts b/examples/with-scss/nuxt.config.ts deleted file mode 100644 index a3e4d68096a..00000000000 --- a/examples/with-scss/nuxt.config.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { defineNuxtConfig } from 'nuxt3' - -export default defineNuxtConfig({ -}) diff --git a/examples/with-scss/package.json b/examples/with-scss/package.json deleted file mode 100644 index 3f868cc9af5..00000000000 --- a/examples/with-scss/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "example-with-scss", - "private": true, - "scripts": { - "build": "nuxt build", - "dev": "nuxt dev", - "start": "node .output/server/index.mjs" - }, - "devDependencies": { - "@types/sass": "^1", - "nuxt3": "latest", - "sass": "^1.42.1" - } -} diff --git a/yarn.lock b/yarn.lock index 5748c366cd7..df12fbe214f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3566,15 +3566,6 @@ __metadata: languageName: node linkType: hard -"@types/sass@npm:^1": - version: 1.16.1 - resolution: "@types/sass@npm:1.16.1" - dependencies: - "@types/node": "*" - checksum: 3f86d2eaf4988a2775fc0fc164d35e73ce82d71228191da7b11d97ad5e8ac129f1c5f798307e31482f8cfebab758bd3b24e731860bed81afe5a1bbe13fa2b2df - languageName: node - linkType: hard - "@types/semver@npm:^7": version: 7.3.8 resolution: "@types/semver@npm:7.3.8" @@ -6474,7 +6465,7 @@ __metadata: languageName: node linkType: hard -"chokidar@npm:3.5.2, chokidar@npm:>=3.0.0 <4.0.0, chokidar@npm:^3.4.1, chokidar@npm:^3.5.1, chokidar@npm:^3.5.2": +"chokidar@npm:3.5.2, chokidar@npm:^3.4.1, chokidar@npm:^3.5.1, chokidar@npm:^3.5.2": version: 3.5.2 resolution: "chokidar@npm:3.5.2" dependencies: @@ -9282,16 +9273,6 @@ __metadata: languageName: unknown linkType: soft -"example-with-scss@workspace:examples/with-scss": - version: 0.0.0-use.local - resolution: "example-with-scss@workspace:examples/with-scss" - dependencies: - "@types/sass": ^1 - nuxt3: latest - sass: ^1.42.1 - languageName: unknown - linkType: soft - "example-with-wasm@workspace:examples/with-wasm": version: 0.0.0-use.local resolution: "example-with-wasm@workspace:examples/with-wasm" @@ -16999,17 +16980,6 @@ fsevents@~2.3.2: languageName: node linkType: hard -"sass@npm:^1.42.1": - version: 1.42.1 - resolution: "sass@npm:1.42.1" - dependencies: - chokidar: ">=3.0.0 <4.0.0" - bin: - sass: sass.js - checksum: 467817475b23a3da3aac2f5e401f3b3d9431845b31ff1bc6269d4677852b4e1445e50d6ed1a8daffa4a76398cff6c531670171823466137ed8c2721c17983973 - languageName: node - linkType: hard - "sax@npm:^1.2.4, sax@npm:~1.2.4": version: 1.2.4 resolution: "sax@npm:1.2.4"