Introducing Global SCSS in VUE-CLI projects

Source: Internet
Author: User

Load a global settings file

It is a common requirement to load a setup file in each component without explicitly importing it each time. For example, use the SCSS variable globally for all components. In order to achieve this goal:

npm install sass-resources-loader --save-dev

Then add the following Webpack rule:

{  ‘sass-resources-loader‘,  options: {    resources: path.resolve(__dirname, ‘../src/style/_variables.scss‘)  }}

For example, if you are using Vuejs-templates/webpack, please modify the following build/utils.js :

scss: generateLoaders(‘sass‘).concat(  {    loader: ‘sass-resources-loader‘,    options: {      resources: path.resolve(__dirname, ‘../src/style/_variables.scss‘)    }  }),

In this file, to avoid duplicate CSS in the final compiled file, it is recommended to include only variables, mixins, and so on.

Source: Vue-loader Official documentation

Https://vue-loader.vuejs.org/zh-cn/configurations/pre-processors.html

Introducing Global SCSS in VUE-CLI projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.