Extracts the style of the page as an external css when rendered on the server side
简体中文 | English
Faster rendering and more readable seo
- 🚠 Optimal Caching
- ⛰ Supports all rendering modes, spa, ssg, ssr and ssr with pre-rendering.
- 🌲 Intelligent minification extraction, removing unused styles from the page, merging duplicate styles
npm i nuxt-style-extractor// nuxt.config.ts
export default defineNuxtConfig({
modules: ["nuxt-style-extractor"],
});That's all. Everything's automatic.
Of course, you can also configure it.
// nuxt.config.ts
export default defineNuxtConfig({
styleExtractor: {
minify: true, // Whether to enable minification
removeUnused: true, // Whether to remove unused styles
},
});// style-extractor.mjs
export default (options) => {
return options.css + "body { background: red }";
};
// nuxt.config.ts
export default defineNuxtConfig({
styleExtractor: {
transformFile: "style-extractor.mjs",
},
});