创建项目
yarn create nuxt-app [项目名]
or
npx create-nuxt-app [项目名]
or
npm init nuxt-app [项目名]
在终端中输入命令后选择配置如下
配置scss
// https://nuxtjs.org/docs/2.x/features/configuration#the-css-property
yarn add -D sass sass-loader
将bulma的变量配置为全局可使用
将bulma的color变量设为全局变量
详情访问:链接
安装bulma
yarn add bulma
在项目根目录下的assets文件夹里新建styles文件夹,然后再新建index.scss,将bulma的css引入
@import 'bulma/sass/utilities/_all.sass';
@import '~bulma';
```vue
> 上面方法虽然能引用bulma的变量,但只能在局部中引用,不能再全局中引用,如果在全局中使用,还得在nuxt.config.js中研究如何配置,于是看完[Eduardo Vedes](https://www.freecodecamp.org/news/author/evedes/)的这篇[文章](https://www.freecodecamp.org/news/up-goind-with-nuxt-js-bulma-and-sass/)中提到了**[@nuxtjs/style-resources](https://www.npmjs.com/package/@nuxtjs/style-resources)可以实现全局配置**
- 在 ` ``nuxt.config.js ` 中添加如下配置:
- css数组中添加全局配置 `css: ['~assets/styles/index.scss']`
- 添加`styleResources` 模块 `styleResources: { scss: ['~assets/styles/index.scss'] }`
- 在`modules`中添加 `'@nuxtjs/style-resources'`
```javascript
// nuxt.config.js
export default {
// Global page headers (https://go.nuxtjs.dev/config-head)
head: {
title: 'lin-blog',
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{ hid: 'description', name: 'description', content: '' },
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},
// Global CSS (https://go.nuxtjs.dev/config-css)
css: ['~assets/styles/index.scss'],
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: [],
// Auto import components (https://go.nuxtjs.dev/config-components)
components: true,
// Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
// https://go.nuxtjs.dev/stylelint
'@nuxtjs/stylelint-module',
],
styleResources: {
scss: ['~assets/styles/index.scss'],
},
// Modules (https://go.nuxtjs.dev/config-modules)
modules: [
// https://github.com/nuxt-community/style-resources-module
'@nuxtjs/style-resources',
// https://go.nuxtjs.dev/bootstrap
'@nuxtjs/bulma',
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
],
// Axios module configuration (https://go.nuxtjs.dev/config-axios)
axios: {},
// Build Configuration (https://go.nuxtjs.dev/config-build)
build: {
postcss: {
preset: {
features: {
customProperties: false,
},
},
},
},
};
更简单的配置:
nuxt.config.js中的build里添加loaders配置:
build: {
// ...其他配置
// 以下为新增配置
loaders: {
sass: {
prependData: "@import '~bulma/sass/utilities/_all.sass;",
},
},
},
完整配置如下:
// nuxt.config.js
export default {
// Global page headers (https://go.nuxtjs.dev/config-head)
head: {
title: 'lin',
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{ hid: 'description', name: 'description', content: '' },
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},
// Global CSS (https://go.nuxtjs.dev/config-css)
css: [],
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: [],
// Auto import components (https://go.nuxtjs.dev/config-components)
components: true,
// Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
],
// Modules (https://go.nuxtjs.dev/config-modules)
modules: [
// https://go.nuxtjs.dev/bootstrap
'@nuxtjs/bulma',
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
],
// Axios module configuration (https://go.nuxtjs.dev/config-axios)
axios: {},
// Build Configuration (https://go.nuxtjs.dev/config-build)
build: {
postcss: {
preset: {
features: {
customProperties: false,
},
},
},
loaders: {
sass: {
prependData: "@import '~bulma/sass/utilities/_all.sass;",
},
},
},
};