Skip to content

Commit 45ad0be

Browse files
chore: next (#748)
1 parent 194fea4 commit 45ad0be

34 files changed

+93615
-2331
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
'test/helpers/testLoader.js',
1111
],
1212
rules: {
13-
// temporary disable for test before we migrate on jest
1413
strict: 'off',
1514
},
1615
},

README.md

Lines changed: 144 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,44 @@ Thankfully there are a two solutions to this problem:
107107

108108
## Options
109109

110-
By default all options passed to loader also passed to to [Node Sass](https://github.com/sass/node-sass) or [Dart Sass](http://sass-lang.com/dart-sass)
110+
### `implementation`
111111

112-
> ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
113-
> ℹ️ Options such as `file` and `outFile` are unavailable.
114-
> ℹ️ Only the "expanded" and "compressed" values of outputStyle are supported for `dart-sass`.
115-
> ℹ We recommend don't use `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because loader automatically setup this options.
112+
The special `implementation` option determines which implementation of Sass to use.
116113

117-
There is a slight difference between the `node-sass` and `sass` options. We recommend look documentation before used them:
114+
By default the loader resolve the implementation based on your dependencies.
115+
Just add required implementation to `package.json` (`node-sass` or `sass` package) and install dependencies.
118116

119-
- [the Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
120-
- [the Dart Sass documentation](https://github.com/sass/dart-sass#javascript-api) for all available `sass` options.
117+
Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementation:
121118

122-
**webpack.config.js**
119+
**package.json**
120+
121+
```json
122+
{
123+
"devDependencies": {
124+
"sass-loader": "^7.2.0",
125+
"sass": "^1.22.10"
126+
}
127+
}
128+
```
129+
130+
Example where the `sass-loader` loader uses the `node-sass` implementation:
131+
132+
**package.json**
133+
134+
```json
135+
{
136+
"devDependencies": {
137+
"sass-loader": "^7.2.0",
138+
"node-sass": "^4.0.0"
139+
}
140+
}
141+
```
142+
143+
Beware the situation when `node-sass` and `sass` was installed, by default the `sass-loader` prefers `node-sass`, to avoid this situation use the `implementation` option.
144+
145+
It takes either `node-sass` or `sass` (`Dart Sass`) module.
146+
147+
For example, to use Dart Sass, you'd pass:
123148

124149
```js
125150
module.exports = {
@@ -133,8 +158,8 @@ module.exports = {
133158
{
134159
loader: 'sass-loader',
135160
options: {
136-
indentWidth: 4,
137-
includePaths: ['absolute/path/a', 'absolute/path/b'],
161+
// Prefer `dart-sass`
162+
implementation: require('sass'),
138163
},
139164
},
140165
],
@@ -144,44 +169,55 @@ module.exports = {
144169
};
145170
```
146171

147-
### `implementation`
148-
149-
The special `implementation` option determines which implementation of Sass to use.
150-
151-
By default the loader resolve the implementation based on your dependencies.
152-
Just add required implementation to `package.json` (`node-sass` or `sass` package) and install dependencies.
172+
Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
173+
To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.
153174

154-
Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementation:
175+
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
155176

156177
**package.json**
157178

158179
```json
159180
{
160181
"devDependencies": {
161182
"sass-loader": "^7.2.0",
162-
"sass": "^1.22.10"
183+
"sass": "^1.22.10",
184+
"fibers": "^4.0.1"
163185
}
164186
}
165187
```
166188

167-
Example where the `sass-loader` loader uses the `node-sass` implementation:
189+
You can disable automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package pass the `false` value for the `sassOptions.fiber` option.
168190

169-
**package.json**
191+
**webpack.config.js**
170192

171-
```json
172-
{
173-
"devDependencies": {
174-
"sass-loader": "^7.2.0",
175-
"node-sass": "^4.0.0"
176-
}
177-
}
193+
```js
194+
module.exports = {
195+
module: {
196+
rules: [
197+
{
198+
test: /\.s[ac]ss$/i,
199+
use: [
200+
'style-loader',
201+
'css-loader',
202+
{
203+
loader: 'sass-loader',
204+
options: {
205+
implementation: require('sass'),
206+
sassOptions: {
207+
fiber: false,
208+
},
209+
},
210+
},
211+
],
212+
},
213+
],
214+
},
215+
};
178216
```
179217

180-
Beware the situation when `node-sass` and `sass` was installed, by default the `sass-loader` prefers `node-sass`, to avoid this situation use the `implementation` option.
218+
Also you can pass own the `fiber` value using this code:
181219

182-
It takes either `node-sass` or `sass` (`Dart Sass`) module.
183-
184-
For example, to use Dart Sass, you'd pass:
220+
**webpack.config.js**
185221

186222
```js
187223
module.exports = {
@@ -195,8 +231,10 @@ module.exports = {
195231
{
196232
loader: 'sass-loader',
197233
options: {
198-
// Prefer `dart-sass`
199234
implementation: require('sass'),
235+
sassOptions: {
236+
fiber: require('fibers'),
237+
},
200238
},
201239
},
202240
],
@@ -206,10 +244,27 @@ module.exports = {
206244
};
207245
```
208246

209-
Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
210-
To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.
247+
### `sassOptions`
248+
249+
Type: `Object|Function`
250+
251+
Options for [Node Sass](https://github.com/sass/node-sass) or [Dart Sass](http://sass-lang.com/dart-sass) implementation.
252+
253+
> ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
254+
255+
> ℹ️ Options such as `file` and `outFile` are unavailable.
256+
257+
> ℹ We recommend don't use `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because loader automatically setup this options.
258+
259+
There is a slight difference between the `node-sass` and `sass` (`Dart Sass`) options.
260+
We recommend look documentation before used them:
261+
262+
- [the Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
263+
- [the Dart Sass documentation](https://github.com/sass/dart-sass#javascript-api) for all available `sass` options.
264+
265+
#### `Object`
211266

212-
To enable this, pass the `Fiber` class to the `fiber` option:
267+
Setups option as object for sass implementation.
213268

214269
**webpack.config.js**
215270

@@ -225,8 +280,10 @@ module.exports = {
225280
{
226281
loader: 'sass-loader',
227282
options: {
228-
implementation: require('sass'),
229-
fiber: require('fibers'),
283+
sassOptions: {
284+
indentWidth: 4,
285+
includePaths: ['absolute/path/a', 'absolute/path/b'],
286+
},
230287
},
231288
},
232289
],
@@ -236,7 +293,47 @@ module.exports = {
236293
};
237294
```
238295

239-
### `data`
296+
#### `Function`
297+
298+
Allows setup difference options based on loader context.
299+
300+
```js
301+
module.exports = {
302+
module: {
303+
rules: [
304+
{
305+
test: /\.s[ac]ss$/i,
306+
use: [
307+
'style-loader',
308+
'css-loader',
309+
{
310+
loader: 'sass-loader',
311+
options: {
312+
sassOptions: (loaderContext) => {
313+
// More information about available properties https://webpack.js.org/api/loaders/
314+
const { resourcePath, rootContext } = loaderContext;
315+
const relativePath = path.relative(rootContext, resourcePath);
316+
317+
if (relativePath === 'styles/foo.scss') {
318+
return {
319+
includePaths: ['absolute/path/c', 'absolute/path/d'],
320+
};
321+
}
322+
323+
return {
324+
includePaths: ['absolute/path/a', 'absolute/path/b'],
325+
};
326+
},
327+
},
328+
},
329+
],
330+
},
331+
],
332+
},
333+
};
334+
```
335+
336+
### `prependData`
240337

241338
Type: `String|Function`
242339
Default: `undefined`
@@ -262,7 +359,7 @@ module.exports = {
262359
{
263360
loader: 'sass-loader',
264361
options: {
265-
data: '$env: ' + process.env.NODE_ENV + ';',
362+
prependData: '$env: ' + process.env.NODE_ENV + ';',
266363
},
267364
},
268365
],
@@ -286,8 +383,8 @@ module.exports = {
286383
{
287384
loader: 'sass-loader',
288385
options: {
289-
data: (loaderContext) => {
290-
// More information about avalaible options https://webpack.js.org/api/loaders/
386+
prependData: (loaderContext) => {
387+
// More information about available properties https://webpack.js.org/api/loaders/
291388
const { resourcePath, rootContext } = loaderContext;
292389
const relativePath = path.relative(rootContext, resourcePath);
293390

@@ -309,11 +406,11 @@ module.exports = {
309406
### `sourceMap`
310407

311408
Type: `Boolean`
312-
Default: `false`
409+
Default: depends on the `compiler.devtool` value
313410

314411
Enables/Disables generation of source maps.
315412

316-
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not).
413+
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option, all values enable source map generation except `eval` and `false` value.
317414

318415
**webpack.config.js**
319416

@@ -351,7 +448,7 @@ module.exports = {
351448
Type: `Boolean`
352449
Default: `true`
353450

354-
Allows to disable default `webpack` importer.
451+
Enables/Disables default `webpack` importer.
355452

356453
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starts with `~` will not work, but you can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
357454

@@ -424,6 +521,8 @@ module.exports = {
424521

425522
### Source maps
426523

524+
Enables/Disables generation of source maps.
525+
427526
To enable CSS source maps, you'll need to pass the `sourceMap` option to the sass-loader _and_ the css-loader.
428527

429528
**webpack.config.js**

azure-pipelines.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
pool:
3737
vmImage: ubuntu-16.04
3838
strategy:
39-
maxParallel: 5
39+
maxParallel: 4
4040
matrix:
4141
node-12:
4242
node_version: ^12.0.0
@@ -47,9 +47,6 @@ jobs:
4747
node-8:
4848
node_version: ^8.9.0
4949
webpack_version: latest
50-
node-6:
51-
node_version: ^6.9.0
52-
webpack_version: latest
5350
node-8-canary:
5451
node_version: ^8.9.0
5552
webpack_version: next
@@ -91,7 +88,7 @@ jobs:
9188
pool:
9289
vmImage: macOS-10.14
9390
strategy:
94-
maxParallel: 5
91+
maxParallel: 4
9592
matrix:
9693
node-12:
9794
node_version: ^12.0.0
@@ -102,9 +99,6 @@ jobs:
10299
node-8:
103100
node_version: ^8.9.0
104101
webpack_version: latest
105-
node-6:
106-
node_version: ^6.9.0
107-
webpack_version: latest
108102
node-8-canary:
109103
node_version: ^8.9.0
110104
webpack_version: next
@@ -146,7 +140,7 @@ jobs:
146140
pool:
147141
vmImage: windows-2019
148142
strategy:
149-
maxParallel: 5
143+
maxParallel: 4
150144
matrix:
151145
node-12:
152146
node_version: ^12.0.0
@@ -157,9 +151,6 @@ jobs:
157151
node-8:
158152
node_version: ^8.9.0
159153
webpack_version: latest
160-
node-6:
161-
node_version: ^6.9.0
162-
webpack_version: latest
163154
node-8-canary:
164155
node_version: ^8.9.0
165156
webpack_version: next

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (api) => {
1010
'@babel/preset-env',
1111
{
1212
targets: {
13-
node: '6.9.0',
13+
node: '8.9.0',
1414
},
1515
},
1616
],

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
};

0 commit comments

Comments
 (0)