4

I have three .scss files in my Vue project.

The main global one, which I have imported to my main app component. Then, the other two are ones that container variables, and with such cannot be important in the same way, as the variable cannot be found.

So, I created a vue.config.js file, and added -

module.exports = {
css: {
  loaderOptions: {
    sass: {
      data: `@import "@/styles/_variables.scss";`
    },
  }
}
};

The issue is, that imports my _variables.scss file, but I also want to import a _other.scss file (from the same folder).

I cannot figure out how to structure it for it to import and use both.

2
  • 1
    @import "@/styles/_variables.scss"; @import "@/styles/_other.scss" Commented Apr 24, 2019 at 9:44
  • 2
    You can import other scss files in one main file and just import the main scss file Commented Apr 24, 2019 at 9:55

2 Answers 2

9

If you're using sass-loader 8 or above, you need to use prependData instead of data. For example:

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        prependData: `
          @import "@/styles/_variables.scss";
          @import "@/styles/_variables2.scss";
        `
      }
    }
  }
};
Sign up to request clarification or add additional context in comments.

Comments

3
@import "@/styles/_variables.scss"; @import "@/styles/_other.scss"

Worked perfectly. But so did importing into one large file, and loading that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.