css
Nuxt.js 通过 nuxt.config.js 中的选项提供了一种共享全局 CSS 文件的好方法
例子:
// nuxt.config.js
export default {
// other options
css: [
// Load a Node.js module directly (here it's a Sass file)
'bulma',
// CSS file in the project
'@/assets/css/main.css',
// SCSS file in the project
'@/assets/css/main.scss'
],
// other options
}
在您的情况下,您需要添加 sass 和 sass-loader 以在您的项目中加载 sass、scss、less &... 文件。
SASS: yarn add sass-loader sass
LESS: yarn add less-loader less
Stylus: yarn add stylus-loader stylus
分享您的全局样式文件(scss、sass 和 ...)和其他可以使用Nuxt 样式资源的好功能。
在所有样式文件中共享变量、mixins、函数(不需要@import)
使用以下命令中的一个向您的项目添加@nuxtjs/style-resources
依赖项:yarn
npm
yarn add -D @nuxtjs/style-resources
或者npm install --save-dev @nuxtjs/style-resources
然后你可以在 nuxt.config.js 文件中添加'@nuxtjs/style-resources'
选项buildModules
导入你的全局 scss 文件,如下所示:
// nuxt.config.js
export default {
// other options
buildModules: [
'@nuxtjs/style-resources',
],
styleResources: {
// your settings here
scss: ['@/assets/scss/_introPage.scss'],
sass: [],
less: [],
stylus: [],
hoistUseStatements: true // Hoists the "@use" imports. Applies only
to "sass", "scss" and "less". Default: false.
}
// other options
}
有关更多信息,请参阅此链接https://www.npmjs.com/package/@nuxtjs/style-resources