Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

javascript - How To Pass Env Vars to Sass Plugin in Gatsby?

How do I pass environment variables to the gatsby-sass-plugin? I'd like to be able to pass an environment variable into the loader that I can then use in my scss files. This is not well documented and I'm not sure how to do it.

Reference: https://www.gatsbyjs.com/plugins/gatsby-plugin-sass/

This does not work:

{
  resolve: "gatsby-plugin-sass",
  options: {
    additionalData: `$storeName: ${process.env.SHOPIFY_STORE_NAME};`
  }
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to this recent GitHub thread, those options are not directly valid as it:

Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema.

This is causing the options object to be undefined.

Try upgrading your gatsby-plugin-sass to:

[email protected]

Check your node-sass version too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...