Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add ssr styles inject function. #1855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/index.ts
Expand Up @@ -204,9 +204,16 @@ export default function loader(
needsHotReload
)
} else {
stylesCode += `\nimport ${styleRequest}`
// SSR need server inject style
// So here we expose the style's __inject__ function to SFC script
// In Server render function, we can use App.__inject__(context) function to append styles to current context
if(isServer) {
stylesCode += `\nvar style${i} = require(${styleRequest})\n` +
`if (style${i}.__inject__) script.__inject__ = style${i}.__inject__`;
} else {
stylesCode += `\nimport ${styleRequest}`;
}
}
// TODO SSR critical CSS collection
})
}

Expand Down