This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(vite): dev ssr fouc with preprocessors #916
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <template> | ||
| <div class="app"> | ||
| <h1>Hello</h1> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .app { | ||
| font-family: Avenir, Helvetica, Arial, sans-serif; | ||
| padding: 1rem 1.5rem; | ||
|
|
||
| h1 { | ||
| font-size: 4em; | ||
| font-weight: 400; | ||
| } | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { defineNuxtConfig } from 'nuxt3' | ||
|
|
||
| export default defineNuxtConfig({ | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { Plugin } from 'vite' | ||
| import { MOCK_CSS_SUFFIX } from '../utils' | ||
|
|
||
| // For SSR renderer to treat preprocessors as css, | ||
| // we need to append the `.css` in manifest, and then write them back on serving. | ||
| export function mockCSSRewritePlugin () { | ||
| return <Plugin> { | ||
| name: 'nuxt:mock-css-rewrite', | ||
| enforce: 'pre', | ||
| configureServer (server) { | ||
| server.middlewares.use((req, _, next) => { | ||
| if (req.url.endsWith(MOCK_CSS_SUFFIX)) { | ||
| req.url = req.url.slice(0, -MOCK_CSS_SUFFIX.length - 1) | ||
| } | ||
| next() | ||
| }) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,24 @@ export function uniq<T> (arr: T[]): T[] { | |
| } | ||
|
|
||
| const IS_CSS_RE = /\.css(\?[^.]+)?$/ | ||
| const IS_DEV_CSS_RE = /\.(?:css|scss|sass|postcss|less|stylus|styl)(\?[^.]+)?$/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
|
|
||
| export const MOCK_CSS_SUFFIX = '__nuxt_mock.css' | ||
|
|
||
| export function isCSS (file: string) { | ||
| return IS_CSS_RE.test(file) | ||
| } | ||
|
|
||
| export function isDevCSS (file: string) { | ||
| return IS_DEV_CSS_RE.test(file) | ||
| } | ||
|
|
||
| export function rewriteDevCSS (file: string) { | ||
| if (file.endsWith('.css')) { | ||
| return file | ||
| } | ||
| if (file.includes('?')) { | ||
| return file + '&' + MOCK_CSS_SUFFIX | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
| } | ||
| return file + '?' + MOCK_CSS_SUFFIX | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use
resolveIdhook to fix issue?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, what about updating regex in vue-bundle-renderer. Would it fix without workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't know we have control of that package. That would defintely better to be fixed there.