How to pack and detach sass? Introduction to packaging and separating sass methods

Source: Internet
Author: User

This article is about how to package and separate sass? Packaging and separation of sass methods introduced, there is a certain reference value, the need for friends can refer to, I hope to help you.

Foreword: Package.json is the package management profile in NPM, Webpack.config.js is the Webpack default profile, Webpack.plugin.js is the configuration I extracted to make webpack.config.js look clearer, gu The name idea is to extract the configuration of the plug-in.

Node_modules is the installation directory of the dependency package after the NPM install is executed.

Packaging and separating Sass

Install two packages under the project directory:

NPM Install–save-dev Node-sass

NPM Install–save-dev Sass-loader

If the installation is unsuccessful, you will need to remove the Node_modules directory, re-install the directory after NPM install and reinstall the two packages

To write the loader configuration:

Loader configuration should be in order {    test:/\.scss$/, use    : [{        loader: ' Style-loader '//Creates style nodes from JS strings    }, {        loader: ' css-loader '//translates CSS into CommonJS    }, {        loader: ' Sass-loader '//compiles sass to css
  }]}src/index.html insert a layer about SASS <div id= "Sasslearn" ></div>sass file: Create a new Src/css file in Sassle.scss $ Nav-color: #fff; #sassLearn {    $width: 100%;    Width: $width;    height:30px;    Background-color: $nav-color;}

Introduce Sassimport sass from './css/sassle.scss ' webpack after NPM run server in src/entry.js to see the effects (but at this point # Sasslearn is packaged into entry.js) modify useuse:extractTextPlugin.extract in the Sass configuration in Webpack-config.js ({    use:[{      Loader: ' Css-loader '    },{      loader: ' Sass-loader '    }],    fallback: ' Style-loader '  }

Delete the Dist folder Webpack to package, see the DIST/CSS/INDEX.CSS has #sasslearn style settings (that is, the sass and JS files have been separated)

NPM Run server opens a browser for viewing effects

Related Article

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.