Skip to content

Commit

Permalink
fix: nuxt can't work
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Dec 20, 2023
1 parent babfd20 commit f6cbfde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ build

*.mts.timestamp-*

.nuxt
.nuxt
.output
4 changes: 3 additions & 1 deletion examples/nuxt-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "nuxt-demo",
"type": "module",
"scripts": {
"dev": "nuxt dev"
"dev": "nuxt dev",
"build": "nuxt build",
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxt/kit": "^3.8.2",
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ function transformWithStylex(code: string, id: string, transformOptions: Transfo
// But from a design principles. We won't need it. Only using virtual module is enough.
// Judging from the previous experimental implementation of style9,It's worth to do it.

const VIRTUAL_STYLEX_MODULE = '\0stylex:virtual'
// I don't understand why nuxt has to handle virtual module. so i had to change the name :(
// And ensure that the middleware only process the correct request headers.
const VIRTUAL_STYLEX_MODULE = '\0vite-plugin:stylex'

const VIRTUAL_STYLEX_CSS_MODULE = VIRTUAL_STYLEX_MODULE + '.css'
const VIRTUAL_STYLEX_CSS_MODULE = 'vite-plugin:stylex.css'

const VITE_INTERNAL_CSS_PLUGIN_NAMES = ['vite:css', 'vite:css-post']

Expand All @@ -71,7 +73,7 @@ function createSSRMiddleware(processStylexRules: () => string): NextHandleFuncti
const { host } = req.headers
const url = new URL(req.originalUrl, `${protocol}://${host}`)
// Check style sheet is registered.
if (url.pathname.endsWith('.css') && url.pathname.includes('stylex:virtual')) {
if (url.pathname.endsWith('.css') && url.pathname.includes('vite-plugin:stylex') && req.headers['content-type'] === 'text/css') {
res.setHeader('Content-Type', 'text/css')
res.end(processStylexRules())
return
Expand Down

0 comments on commit f6cbfde

Please sign in to comment.