Install Sass
yarn add node-sass -g node-sass -v node-sass 4.5.1 (Wrapper) [JavaScript] libsass 3.5.0.beta.2 (Sass Compiler) [C/C++]
node-sass src/style.scss dest/style.css
node-sass src/style.scss dest/style.css -w
node-sass --help
Cooperate with webpack2
The sass-loader requires node-sass and webpack as peerDependency. Thus you are able to control the versions accurately.
"peerDependencies": { "node-sass": "^4.0.0", "webpack": "^2.0.0" },
yarn add node-sass sass-loader css-loader style-loader --dev
Style Tag Inline
module.exports = { module: { rules: [ { test: /\.(scss|css)$/, use:[ 'style-loader','css-loader','sass-loader'], }, ], }, };
Style tag outreach
yarn add extract-text-webpack-plugin --dev
const ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { module: { rules: [ { test: /\.(scss|css)$/, use: ExtractTextPlugin.extract({ use:[ 'css-loader','sass-loader'], fallback: 'style-loader', }), }, ], }, plugins: [ new ExtractTextPlugin({ filename: 'index.css', disable: false, allChunks: true, }), ], };
Support CSS Modules
module: { rules: [ { test: /\.(scss|css)$/, use: ExtractTextPlugin.extract({ use:[ { loader: 'css-loader', options:{ modules:true, importLoaders:1, localIdentName:'[local]_[hash:base64:5]', sourceMap: true, }, }, { loader:'sass-loader', options:{ sourceMap: true, }, }, ], fallback: 'style-loader', }), }, ], },
error handling
Module build failed: Error: ENOENT: no such file or directory
reference resources
-
github.com/webpack-contrib/sass-loader/blob/master/package.json -
github.com/sass/node-sass -
webpack.js.org/loaders/sass-loader/