admin管理员组文章数量:1332403
I'm confused with the Nuxt.js SCSS pilation...
I have the assets folder and it has two SCSS files included in nuxt.config.js
:
// Global CSS (/config-css)
css: [
'~assets/scss/bootstrap.scss',
'~assets/scss/main.scss'
],
Launch npm run build
and then npm run generate
, then I go into the dist folder and open the index.html file, what I see is all css (and it is too big) inside the style tag on the page:
Nuxt.js has piled the SCSS files from assets and put CSS in the style tag. How put into a file and connect with link tag in the head section like this?
<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="/css/main.css">
You may say I can use head settings in nuxt.config.js
, but I cannot because it is possible only with remote and static files, it does not work like this:
head: {
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=0, shrink-to-fit=no' },
{ hid: 'description', name: 'description', content: '' }
],
link: [
{ rel: 'stylesheet', href: '~/assets/scss/bootstrap.scss' },
{ rel: 'stylesheet', href: '~/assets/scss/main.scss' },
{ rel: 'icon', type: 'image/svg+xml', href: '/images/logo.svg' },
],
script: []
},
I did not find in the Nuxt.js documentation how put the Global CSS to a file. Is it possible with Nuxt.js config or change the Webpack build config only? Help me understand please :-)
I'm confused with the Nuxt.js SCSS pilation...
I have the assets folder and it has two SCSS files included in nuxt.config.js
:
// Global CSS (https://go.nuxtjs.dev/config-css)
css: [
'~assets/scss/bootstrap.scss',
'~assets/scss/main.scss'
],
Launch npm run build
and then npm run generate
, then I go into the dist folder and open the index.html file, what I see is all css (and it is too big) inside the style tag on the page:
Nuxt.js has piled the SCSS files from assets and put CSS in the style tag. How put into a file and connect with link tag in the head section like this?
<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="/css/main.css">
You may say I can use head settings in nuxt.config.js
, but I cannot because it is possible only with remote and static files, it does not work like this:
head: {
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=0, shrink-to-fit=no' },
{ hid: 'description', name: 'description', content: '' }
],
link: [
{ rel: 'stylesheet', href: '~/assets/scss/bootstrap.scss' },
{ rel: 'stylesheet', href: '~/assets/scss/main.scss' },
{ rel: 'icon', type: 'image/svg+xml', href: '/images/logo.svg' },
],
script: []
},
I did not find in the Nuxt.js documentation how put the Global CSS to a file. Is it possible with Nuxt.js config or change the Webpack build config only? Help me understand please :-)
Share Improve this question asked Feb 12, 2021 at 16:49 eleaveeleave 1272 silver badges10 bronze badges1 Answer
Reset to default 8You can use the extractCSS
build option to extract all your CSS assets into separate files (usually one per ponent) and allows you to put in cache each CSS file:
// nuxt.config.js
export default {
build: {
extractCSS: true
}
}
本文标签: javascriptNuxtjs How move Global CSS from style tag to css fileStack Overflow
版权声明:本文标题:javascript - Nuxt.js: How move Global CSS from style tag to css file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742235206a2437951.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论