@@ -34,7 +34,7 @@ module.exports = {
34
34
rules: [
35
35
{
36
36
test: / \. styl$ / ,
37
- loader: ' stylus-loader' , // compiles Styl to CSS
37
+ loader: " stylus-loader" , // compiles Styl to CSS
38
38
},
39
39
],
40
40
},
@@ -75,13 +75,13 @@ module.exports = {
75
75
test: / \. styl$ / ,
76
76
use: [
77
77
{
78
- loader: ' style-loader' ,
78
+ loader: " style-loader" ,
79
79
},
80
80
{
81
- loader: ' css-loader' ,
81
+ loader: " css-loader" ,
82
82
},
83
83
{
84
- loader: ' stylus-loader' ,
84
+ loader: " stylus-loader" ,
85
85
options: {
86
86
stylusOptions: {
87
87
/**
@@ -91,23 +91,23 @@ module.exports = {
91
91
* @type {(string|Function)[]}
92
92
* @default []
93
93
*/
94
- use: [' nib' ],
94
+ use: [" nib" ],
95
95
96
96
/**
97
97
* Add path(s) to the import lookup paths.
98
98
*
99
99
* @type {string[]}
100
100
* @default []
101
101
*/
102
- include: [path .join (__dirname , ' src/styl/config' )],
102
+ include: [path .join (__dirname , " src/styl/config" )],
103
103
104
104
/**
105
105
* Import the specified Stylus files/paths.
106
106
*
107
107
* @type {string[]}
108
108
* @default []
109
109
*/
110
- import: [' nib' , path .join (__dirname , ' src/styl/mixins' )],
110
+ import: [" nib" , path .join (__dirname , " src/styl/mixins" )],
111
111
112
112
/**
113
113
* Define Stylus variables or functions.
@@ -117,8 +117,8 @@ module.exports = {
117
117
*/
118
118
// Array is the recommended syntax: [key, value, raw]
119
119
define: [
120
- [' $development' , process .env .NODE_ENV === ' development' ],
121
- [' rawVar' , 42 , true ],
120
+ [" $development" , process .env .NODE_ENV === " development" ],
121
+ [" rawVar" , 42 , true ],
122
122
],
123
123
// Object is deprecated syntax (there is no possibility to specify "raw')
124
124
// define: {
@@ -196,24 +196,24 @@ module.exports = {
196
196
{
197
197
test: / \. styl/ ,
198
198
use: [
199
- ' style-loader' ,
200
- ' css-loader' ,
199
+ " style-loader" ,
200
+ " css-loader" ,
201
201
{
202
- loader: ' stylus-loader' ,
202
+ loader: " stylus-loader" ,
203
203
options: {
204
204
stylusOptions : (loaderContext ) => {
205
205
// More information about available properties https://webpack.js.org/api/loaders/
206
206
const { resourcePath , rootContext } = loaderContext;
207
207
const relativePath = path .relative (rootContext, resourcePath);
208
208
209
- if (relativePath === ' styles/foo.styl' ) {
209
+ if (relativePath === " styles/foo.styl" ) {
210
210
return {
211
- paths: [' absolute/path/c' , ' absolute/path/d' ],
211
+ paths: [" absolute/path/c" , " absolute/path/d" ],
212
212
};
213
213
}
214
214
215
215
return {
216
- paths: [' absolute/path/a' , ' absolute/path/b' ],
216
+ paths: [" absolute/path/a" , " absolute/path/b" ],
217
217
};
218
218
},
219
219
},
@@ -238,15 +238,15 @@ module.exports = {
238
238
{
239
239
test: / \. styl$ / i ,
240
240
use: [
241
- ' style-loader' ,
241
+ " style-loader" ,
242
242
{
243
- loader: ' css-loader' ,
243
+ loader: " css-loader" ,
244
244
options: {
245
245
sourceMap: true ,
246
246
},
247
247
},
248
248
{
249
- loader: ' stylus-loader' ,
249
+ loader: " stylus-loader" ,
250
250
options: {
251
251
sourceMap: true ,
252
252
},
@@ -277,10 +277,10 @@ module.exports = {
277
277
{
278
278
test: / \. styl/ i ,
279
279
use: [
280
- ' style-loader' ,
281
- ' css-loader' ,
280
+ " style-loader" ,
281
+ " css-loader" ,
282
282
{
283
- loader: ' stylus-loader' ,
283
+ loader: " stylus-loader" ,
284
284
options: {
285
285
webpackImporter: false ,
286
286
},
@@ -313,10 +313,10 @@ module.exports = {
313
313
{
314
314
test: / \. styl/ ,
315
315
use: [
316
- ' style-loader' ,
317
- ' css-loader' ,
316
+ " style-loader" ,
317
+ " css-loader" ,
318
318
{
319
- loader: ' stylus-loader' ,
319
+ loader: " stylus-loader" ,
320
320
options: {
321
321
additionalData: ` @env: ${ process .env .NODE_ENV } ;` ,
322
322
},
@@ -330,28 +330,64 @@ module.exports = {
330
330
331
331
#### ` Function `
332
332
333
+ ##### Sync
334
+
333
335
``` js
334
336
module .exports = {
335
337
module: {
336
338
rules: [
337
339
{
338
340
test: / \. styl/ ,
339
341
use: [
340
- ' style-loader' ,
341
- ' css-loader' ,
342
+ " style-loader" ,
343
+ " css-loader" ,
342
344
{
343
- loader: ' stylus-loader' ,
345
+ loader: " stylus-loader" ,
344
346
options: {
345
347
additionalData : (content , loaderContext ) => {
346
348
// More information about available properties https://webpack.js.org/api/loaders/
347
349
const { resourcePath , rootContext } = loaderContext;
348
350
const relativePath = path .relative (rootContext, resourcePath);
349
351
350
- if (relativePath === ' styles/foo.styl' ) {
351
- return ' value = 100px' + content;
352
+ if (relativePath === " styles/foo.styl" ) {
353
+ return " value = 100px" + content;
354
+ }
355
+
356
+ return " value 200px" + content;
357
+ },
358
+ },
359
+ },
360
+ ],
361
+ },
362
+ ],
363
+ },
364
+ };
365
+ ```
366
+
367
+ ##### Async
368
+
369
+ ``` js
370
+ module .exports = {
371
+ module: {
372
+ rules: [
373
+ {
374
+ test: / \. styl/ ,
375
+ use: [
376
+ " style-loader" ,
377
+ " css-loader" ,
378
+ {
379
+ loader: " stylus-loader" ,
380
+ options: {
381
+ additionalData: async (content , loaderContext ) => {
382
+ // More information about available properties https://webpack.js.org/api/loaders/
383
+ const { resourcePath , rootContext } = loaderContext;
384
+ const relativePath = path .relative (rootContext, resourcePath);
385
+
386
+ if (relativePath === " styles/foo.styl" ) {
387
+ return " value = 100px" + content;
352
388
}
353
389
354
- return ' value 200px' + content;
390
+ return " value 200px" + content;
355
391
},
356
392
},
357
393
},
@@ -378,13 +414,13 @@ module.exports = {
378
414
test: / \. styl$ / ,
379
415
use: [
380
416
{
381
- loader: ' style-loader' , // creates style nodes from JS strings
417
+ loader: " style-loader" , // creates style nodes from JS strings
382
418
},
383
419
{
384
- loader: ' css-loader' , // translates CSS into CommonJS
420
+ loader: " css-loader" , // translates CSS into CommonJS
385
421
},
386
422
{
387
- loader: ' stylus-loader' , // compiles Stylus to CSS
423
+ loader: " stylus-loader" , // compiles Stylus to CSS
388
424
},
389
425
],
390
426
},
@@ -401,21 +437,21 @@ To enable sourcemaps for CSS, you'll need to pass the `sourceMap` property in th
401
437
402
438
``` javascript
403
439
module .exports = {
404
- devtool: ' source-map' , // any "source-map"-like devtool is possible
440
+ devtool: " source-map" , // any "source-map"-like devtool is possible
405
441
module: {
406
442
rules: [
407
443
{
408
444
test: / \. styl$ / ,
409
445
use: [
410
- ' style-loader' ,
446
+ " style-loader" ,
411
447
{
412
- loader: ' css-loader' ,
448
+ loader: " css-loader" ,
413
449
options: {
414
450
sourceMap: true ,
415
451
},
416
452
},
417
453
{
418
- loader: ' stylus-loader' ,
454
+ loader: " stylus-loader" ,
419
455
options: {
420
456
sourceMap: true ,
421
457
},
@@ -439,17 +475,17 @@ module.exports = {
439
475
test: / \. styl$ / ,
440
476
use: [
441
477
{
442
- loader: ' style-loader' , // creates style nodes from JS strings
478
+ loader: " style-loader" , // creates style nodes from JS strings
443
479
},
444
480
{
445
- loader: ' css-loader' , // translates CSS into CommonJS
481
+ loader: " css-loader" , // translates CSS into CommonJS
446
482
},
447
483
{
448
- loader: ' stylus-loader' , // compiles Stylus to CSS
484
+ loader: " stylus-loader" , // compiles Stylus to CSS
449
485
options: {
450
486
stylusOptions: {
451
- use: [require (' nib' )()],
452
- import: [' nib' ],
487
+ use: [require (" nib" )()],
488
+ import: [" nib" ],
453
489
},
454
490
},
455
491
},
@@ -487,14 +523,14 @@ module.exports = {
487
523
{
488
524
test: / \. styl$ / ,
489
525
use: [
490
- ' style-loader' ,
491
- ' css-loader' ,
526
+ " style-loader" ,
527
+ " css-loader" ,
492
528
{
493
- loader: ' stylus-loader' ,
529
+ loader: " stylus-loader" ,
494
530
options: {
495
531
stylusOptions: {
496
532
// Specify the path. where to find files
497
- paths: [' node_modules/vars' ],
533
+ paths: [" node_modules/vars" ],
498
534
},
499
535
},
500
536
},
@@ -539,16 +575,16 @@ module.exports = {
539
575
test: / \. styl/ ,
540
576
use: [
541
577
{
542
- loader: ' style-loader' ,
578
+ loader: " style-loader" ,
543
579
},
544
580
{
545
- loader: ' css-loader' ,
581
+ loader: " css-loader" ,
546
582
},
547
583
{
548
- loader: ' stylus-loader' ,
584
+ loader: " stylus-loader" ,
549
585
options: {
550
586
stylusOptions: {
551
- paths: [path .resolve (__dirname , ' node_modules' )],
587
+ paths: [path .resolve (__dirname , " node_modules" )],
552
588
},
553
589
},
554
590
},
0 commit comments