GithubHelp home page GithubHelp logo

bundle-scss-test's Introduction

Bundle Scss Test

The Problem

When respectively import src/style/button.scss and src/style/select.scss, the src/style/vars.scss styles will be bundled twice in the output dist/style.css.

// src/style/vars.scss
$color-primary: #339af0;

:root {
  --color-primary: #{$color-primary};
}
/* dist/style.css */
:root{--color-primary: #339af0}
/* ... */
:root{--color-primary: #339af0}

Test Case 1

Directly import src/style/index.scss, the src/style/vars.scss only be bundled once.

// src/style/index.scss
@forward './button.scss';
@forward './select.scss';

Test Case 2

Toggle the style &--m1 &__el in src/style/button.scss, the src/style/vars.scss only be bundled once.

// src/style/button.scss
@use './vars.scss';

.button {
  color: var(--color-primary);

  // comment out this style
  // &--m1 &__el {
  //   opacity: 60%;
  // }

  &--m2 &__el {
    opacity: 60%;
  }
}

Change the style &--m1 &__el defference to &--m2 &__el, the src/style/vars.scss only be bundled once.

// src/style/button.scss
@use './vars.scss';

.button {
  color: var(--color-primary);

  // change this style value
  &--m1 &__el {
    opacity: 0.6; // also the truth value of 0.6 is same to 60%, there will wrok normally
  }

  &--m2 &__el {
    opacity: 60%;
  }
}

bundle-scss-test's People

Contributors

qmhc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.