[英]How to import whole SCSS folder in Vue Nuxt project?
在我的公司,我们没有在 Vue 文件中编写 css,我们更喜欢使用SCSS
的旧方式。
问题是,我们最终需要在styles.scss
创建新组件时在styles.scss
中编写新的导入,这在更大的项目中确实让我感到styles.scss
。
不久前,当我在 React 中进行开发时,我在webpack.config
文件中导入了名为node-sass-glob-importer
模块, webpack.config
调整了一下( 您可以在此处查看)并且它起作用了 - 我可以像这样导入文件夹: @import "components/**";
在 Nuxt 中,我只有nuxt.config.js
文件,我有点迷失了。 我知道如何在那里扩展一些简单的东西,但这似乎更复杂。
导入node-sass-glob-importer
或以其他方式做同样的事情有什么帮助吗?
如何使用https://github.com/nuxt-community/style-resources-module然后:
export default {
modules: ['@nuxtjs/style-resources'],
styleResources: {
scss: [
'./assets/yourFolder/*.scss'
]
}
}
您可以像这样在 Nuxt 中使用node-sass-glob-importer
:
nuxt.config.js:
const globImporter = require('node-sass-glob-importer');
export default {
...
css: [
'~/assets/scss/global.scss'
],
...
build: {
extend(config, {loaders: {scss}}) {
const sassOptions = scss.sassOptions || {};
sassOptions.importer = globImporter();
scss.sassOptions = sassOptions;
}
}
}
global.scss:
@import "./assets/scss/base/*";
@import "./assets/scss/components/*";
styleResources 用于诸如变量、mixin 和函数之类的东西,您希望在 SCSS 中的任何地方使用,而无需导入文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.