基本配置 - 图2

创建项目

  1. yarn create nuxt-app [项目名]
  2. or
  3. npx create-nuxt-app [项目名]
  4. or
  5. npm init nuxt-app [项目名]

在终端中输入命令后选择配置如下

image.png
项目创建好后就会出现如下图所示
image.png

配置scss

  1. // https://nuxtjs.org/docs/2.x/features/configuration#the-css-property
  2. yarn add -D sass sass-loader

将bulma的变量配置为全局可使用

将bulma的color变量设为全局变量

详情访问:链接

  • 安装bulma

    1. yarn add bulma
  • 在项目根目录下的assets文件夹里新建styles文件夹,然后再新建index.scss,将bulma的css引入

    1. @import 'bulma/sass/utilities/_all.sass';
    2. @import '~bulma';

    ```vue

  1. > 上面方法虽然能引用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)可以实现全局配置**
  2. - ` ``nuxt.config.js ` 中添加如下配置:
  3. - css数组中添加全局配置 `css: ['~assets/styles/index.scss']`
  4. - 添加`styleResources` 模块 `styleResources: { scss: ['~assets/styles/index.scss'] }`
  5. - `modules`中添加 `'@nuxtjs/style-resources'`
  6. ```javascript
  7. // nuxt.config.js
  8. export default {
  9. // Global page headers (https://go.nuxtjs.dev/config-head)
  10. head: {
  11. title: 'lin-blog',
  12. meta: [
  13. { charset: 'utf-8' },
  14. {
  15. name: 'viewport',
  16. content: 'width=device-width, initial-scale=1',
  17. },
  18. { hid: 'description', name: 'description', content: '' },
  19. ],
  20. link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  21. },
  22. // Global CSS (https://go.nuxtjs.dev/config-css)
  23. css: ['~assets/styles/index.scss'],
  24. // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  25. plugins: [],
  26. // Auto import components (https://go.nuxtjs.dev/config-components)
  27. components: true,
  28. // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  29. buildModules: [
  30. // https://go.nuxtjs.dev/eslint
  31. '@nuxtjs/eslint-module',
  32. // https://go.nuxtjs.dev/stylelint
  33. '@nuxtjs/stylelint-module',
  34. ],
  35. styleResources: {
  36. scss: ['~assets/styles/index.scss'],
  37. },
  38. // Modules (https://go.nuxtjs.dev/config-modules)
  39. modules: [
  40. // https://github.com/nuxt-community/style-resources-module
  41. '@nuxtjs/style-resources',
  42. // https://go.nuxtjs.dev/bootstrap
  43. '@nuxtjs/bulma',
  44. // https://go.nuxtjs.dev/axios
  45. '@nuxtjs/axios',
  46. ],
  47. // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  48. axios: {},
  49. // Build Configuration (https://go.nuxtjs.dev/config-build)
  50. build: {
  51. postcss: {
  52. preset: {
  53. features: {
  54. customProperties: false,
  55. },
  56. },
  57. },
  58. },
  59. };

更简单的配置:

此方法也是借鉴Serhan C.的分享:链接

nuxt.config.js中的build里添加loaders配置:

  1. build: {
  2. // ...其他配置
  3. // 以下为新增配置
  4. loaders: {
  5. sass: {
  6. prependData: "@import '~bulma/sass/utilities/_all.sass;",
  7. },
  8. },
  9. },

完整配置如下:

  1. // nuxt.config.js
  2. export default {
  3. // Global page headers (https://go.nuxtjs.dev/config-head)
  4. head: {
  5. title: 'lin',
  6. meta: [
  7. { charset: 'utf-8' },
  8. {
  9. name: 'viewport',
  10. content: 'width=device-width, initial-scale=1',
  11. },
  12. { hid: 'description', name: 'description', content: '' },
  13. ],
  14. link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  15. },
  16. // Global CSS (https://go.nuxtjs.dev/config-css)
  17. css: [],
  18. // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  19. plugins: [],
  20. // Auto import components (https://go.nuxtjs.dev/config-components)
  21. components: true,
  22. // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  23. buildModules: [
  24. // https://go.nuxtjs.dev/eslint
  25. '@nuxtjs/eslint-module',
  26. ],
  27. // Modules (https://go.nuxtjs.dev/config-modules)
  28. modules: [
  29. // https://go.nuxtjs.dev/bootstrap
  30. '@nuxtjs/bulma',
  31. // https://go.nuxtjs.dev/axios
  32. '@nuxtjs/axios',
  33. ],
  34. // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  35. axios: {},
  36. // Build Configuration (https://go.nuxtjs.dev/config-build)
  37. build: {
  38. postcss: {
  39. preset: {
  40. features: {
  41. customProperties: false,
  42. },
  43. },
  44. },
  45. loaders: {
  46. sass: {
  47. prependData: "@import '~bulma/sass/utilities/_all.sass;",
  48. },
  49. },
  50. },
  51. };