首页 > 解决方案 > 如何使用 gatsby 插件将 CSS 更改为 SASS?

问题描述

我正在尝试将我的 CSS 更改为 SASS。为了实现这一点,我安装了 gatsby-plugin-sass,但是每当我执行它时,我都会收到一个错误。我该如何解决这个错误?

这是安装 gatsby-plugin-sass 后我的 gatsby-config.js 的样子:

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-sass`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    'gatsby-transformer-remark'
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

这就是我尝试使用 sass 代码的方式:

$font-stack : Roboto;
$primary-color : 'orange';

h1{
  font-family: $font-stack;
  color: $primary-color
}

我收到的错误如下:

Module parse failed: Unexpected token (1:12)
You may need an appropriate loader to handle this file type.
> $font-stack : Roboto;  
| $primary-color : 'orange';  
|

我该如何解决这个错误?

标签: reactjsgatsby

解决方案


推荐阅读