Skip to content
This repository was archived by the owner on May 29, 2022. It is now read-only.

Commit b50116d

Browse files
Holi0317niieani
authored andcommitted
doc(README): initial readme (#26)
* doc(README): initial readme * add warning about LoaderOptionsPlugin
1 parent 52730c3 commit b50116d

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

README.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,91 @@
1-
# config-sass
2-
Easy Webpack configuration module for using Sass in your Webpack applications.
1+
# @easy-webpack/config-sass
2+
[Sass](http://sass-lang.com/) is a CSS pre-processor. This configuration enable you to compile Sass file and include in your webpack bundle.
3+
4+
[sass-loader](https://github.com/jtangelder/sass-loader) is used in this config.
5+
6+
This use [config-css](https://github.com/easy-webpack/config-css) to achieve loading of CSS module. It is highly recommended to read the documentation of config-css before using this module.
7+
8+
# Installation
9+
```
10+
npm install --save-dev @easy-webpack/config-sass
11+
```
12+
[easy-webpack](https://github.com/easy-webpack/core) is also required.
13+
14+
# Usage
15+
```js
16+
// webpack.config.js
17+
const generateConfig = require('@easy-webpack/core').generateConfig;
18+
19+
const baseConfig = { ... }; // project-specific config like the entry file
20+
21+
module.exports = generateConfig(
22+
baseConfig,
23+
24+
require('@easy-webpack/config-sass')
25+
({/* Options object */ filename: 'styles.css', allChunks: true, sourceMap: false })
26+
);
27+
28+
// This config will compile sass file imported and generate a CSS file named 'style.css' on output path
29+
```
30+
31+
# Options
32+
All options (except the below one) are identical to that of config-css. Please refer to their [documentation](https://github/com/easy-webpack/config-css#options).
33+
34+
### additionalLoaders
35+
Type: `string[]` Default: `[]`
36+
37+
This option need special notice as it may cause confusion.
38+
39+
All loaders string in this config option array will be append __before__ sass-loader.
40+
41+
For example,
42+
43+
```js
44+
const generateConfig = require('@easy-webpack/core').generateConfig;
45+
46+
generateConfig(
47+
require('@easy-webpack/config-sass')
48+
({ additionalLoaders: ['postcss-loader'], extractText: false })
49+
)
50+
51+
// Final loader string will be 'style-loader!css-loader!postcss-loader!sass-loader'
52+
```
53+
54+
# Tips
55+
## Pass in options to sass compiler
56+
Please refer to [options of node-sass](https://github.com/sass/node-sass#options) for all available options.
57+
58+
In Webpack 1, pass in options can be achieved by adding a `sassLoader` property on webpack config.
59+
60+
In Webpack 2, a [loader-options-plugin](https://webpack.js.org/plugins/loader-options-plugin/) must be used to pass in options. Note that you may only use this plugin once with a given test, as it will override *all the options* once used and can cause problems.
61+
62+
```js
63+
const path = require('path');
64+
const webpack = require('webpack');
65+
const generateConfig = require('@easy-webpack/core').generateConfig;
66+
67+
// webpack 1
68+
generateConfig(
69+
require('@easy-webpack/config-sass')(),
70+
{
71+
sassLoader: {
72+
includePaths: [path.resolve('node_modules/material-design-lite/src')]
73+
}
74+
}
75+
);
76+
77+
// webpack 2
78+
generateConfig(
79+
require('@easy-webpack/config-sass')(),
80+
{
81+
plugins: [new webpack.LoaderOptionsPlugin({
82+
test: /\.s[ac]ss$/i,
83+
options: {
84+
sassLoader: {
85+
includePaths: [path.resolve('node_modules/material-design-lite/src')]
86+
}
87+
}
88+
})]
89+
}
90+
)
91+
```

0 commit comments

Comments
 (0)