You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-25Lines changed: 37 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@
13
13
14
14
# stylus-loader
15
15
16
-
A Stylus loader for webpack. Compiles Styl to CSS.
16
+
A Stylus loader for webpack. Compiles Stylus files into CSS.
17
17
18
18
## Getting Started
19
19
@@ -35,7 +35,7 @@ or
35
35
pnpm add -D stylus stylus-loader
36
36
```
37
37
38
-
Then add the loader to your `webpack`config. For example:
38
+
Then add the loader to your `webpack`configuration. For example:
39
39
40
40
**webpack.config.js**
41
41
@@ -52,7 +52,7 @@ module.exports = {
52
52
};
53
53
```
54
54
55
-
And run `webpack` via your preferred method.
55
+
Finally, run `webpack`using the method you normally use (e.g., via CLI or an npm script).
56
56
57
57
## Options
58
58
@@ -84,9 +84,11 @@ type stylusOptions =
84
84
85
85
Default: `{}`
86
86
87
-
You can pass any Stylus specific options to the `stylus-loader` through the `stylusOptions` property in the [loader options](https://webpack.js.org/configuration/module/#ruleoptions--rulequery)
87
+
You can pass any Stylus specific options to the `stylus-loader` through the `stylusOptions` property in the [loader options](https://webpack.js.org/configuration/module/#ruleoptions--rulequery).
88
+
88
89
See the [Stylus documentation](https://stylus-lang.com/docs/js.html).
89
-
Options in dash-case should use camelCase.
90
+
91
+
Options in dash-case should be written in camelCase.
90
92
91
93
#### `object`
92
94
@@ -299,7 +301,7 @@ type webpackImporter = boolean;
299
301
300
302
Default: `true`
301
303
302
-
Enables/Disables the default Webpack importer.
304
+
Enables/disables the default Webpack importer.
303
305
304
306
This can improve performance in some cases.
305
307
Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
@@ -345,13 +347,14 @@ type additionalData =
345
347
Default: `undefined`
346
348
347
349
Prepends `Stylus` code before the actual entry file.
348
-
In this case, the `stylus-loader` will not override the source but just**prepend** the entry's content.
350
+
In this case, the `stylus-loader` will not override the source but will simply**prepend** the entry's content.
349
351
350
-
This is especially useful when some of your Stylus variables depend on the environment:
352
+
This is especially useful when some of your Stylus variables depend on the environment.
351
353
352
354
> [!NOTE]
353
355
>
354
-
> Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this, like multiple Stylus entry files.
356
+
> Since you're injecting code, this will break the source mappings in your entry file.
357
+
> Often there's a simpler solution than this, such as using multiple Stylus entry files.
355
358
356
359
#### `string`
357
360
@@ -402,7 +405,7 @@ module.exports = {
402
405
return"value = 100px"+ content;
403
406
}
404
407
405
-
return"value 200px"+ content;
408
+
return"value = 200px"+ content;
406
409
},
407
410
},
408
411
},
@@ -436,7 +439,7 @@ module.exports = {
436
439
return"value = 100px"+ content;
437
440
}
438
441
439
-
return"value 200px"+ content;
442
+
return"value = 200px"+ content;
440
443
},
441
444
},
442
445
},
@@ -455,7 +458,8 @@ Type:
455
458
typeimplementation=Function|string;
456
459
```
457
460
458
-
The special `implementation` option determines which implementation of Stylus to use. Overrides the locally installed `peerDependency` version of `stylus`.
461
+
The `implementation` option allows you to specify which `Stylus implementation` to use.
462
+
It overrides the locally installed `peerDependency` version of `stylus`.
459
463
460
464
#### `function`
461
465
@@ -511,9 +515,9 @@ module.exports = {
511
515
512
516
## Examples
513
517
514
-
### Normal usage
518
+
### Normal Usage
515
519
516
-
Chain the `stylus-loader` with the [`css-loader`](https://github.com/webpack-contrib/css-loader) and the[`style-loader`](https://github.com/webpack-contrib/style-loader) to immediately apply all styles to the DOM.
520
+
Chain `stylus-loader` with the [`css-loader`](https://github.com/webpack-contrib/css-loader) and [`style-loader`](https://github.com/webpack-contrib/style-loader) to immediately apply all styles to the DOM.
517
521
518
522
**webpack.config.js**
519
523
@@ -542,7 +546,8 @@ module.exports = {
542
546
543
547
### Source maps
544
548
545
-
To enable sourcemaps for CSS, you'll need to pass the `sourceMap` property in the loader's options. If this is not passed, the loader will respect the setting for webpack source maps, set in `devtool`.
549
+
To enable sourcemaps for CSS, you'll need to pass the `sourceMap` property in the loader's options.
550
+
If this is not passed, the loader will respect the setting for webpack source maps, set in `devtool`.
546
551
547
552
**webpack.config.js**
548
553
@@ -609,9 +614,9 @@ module.exports = {
609
614
610
615
### Import JSON files
611
616
612
-
Stylus does not provide resolving capabilities in the `json` function.
617
+
Stylus does not provide resolving capabilities in the `json()` function.
613
618
Therefore webpack resolver does not work for `.json` files.
614
-
Use[`stylus resolver`](#stylus-resolver).
619
+
To handle this, use a[`stylus resolver`](#stylus-resolver).
615
620
616
621
**index.styl**
617
622
@@ -654,34 +659,38 @@ module.exports = {
654
659
655
660
### In production
656
661
657
-
Usually, it's recommended to extract the style sheets into a dedicated file in production using the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin). This way your styles are not dependent on JavaScript.
662
+
Usually, it's recommended to extract the style sheets into a dedicated CSS file in production using the [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin). This way your styles are not dependent on JavaScript.
658
663
659
664
### webpack resolver
660
665
661
666
Webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/).
662
667
The `stylus-loader` applies the webpack resolver when processing queries.
663
-
Thus you can import your Stylus modules from `node_modules`.
668
+
Thus you can import your Stylus modules directly from `node_modules`.
664
669
665
670
```styl
666
671
@import 'bootstrap-styl/bootstrap/index.styl';
667
672
```
668
673
669
-
Using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons.
674
+
Using `~` prefix is deprecated and can be removed from your code (**we recommended**), but we still support it for historical reasons.
675
+
670
676
Why you can removed it? The loader will first try to resolve `@import`/`@require` as relative, if it cannot be resolved, the loader will try to resolve `@import`/`@require` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
677
+
671
678
Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
672
679
673
680
```styl
674
681
@import "~bootstrap-styl/bootstrap/index.styl";
675
682
```
676
683
677
-
It's important to only prepend it with `~`, because `~/` resolves to the home-directory.
678
-
Webpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Styl files have no special syntax for importing relative files.
684
+
It's important to only prepend it with `~`, because `~/` resolves to the home-directory, which is different.
685
+
686
+
Webpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Stylus files have no special syntax for importing relative files.
687
+
679
688
Writing `@import "file"` is the same as `@import "./file";`
680
689
681
690
### Stylus resolver
682
691
683
692
If you specify the `paths` option, modules will be searched in the given `paths`.
684
-
This is Stylus default behavior.
693
+
This is the default Stylus behavior.
685
694
686
695
**webpack.config.js**
687
696
@@ -715,7 +724,9 @@ module.exports = {
715
724
716
725
### Extracting style sheets
717
726
718
-
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/) in development. In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution. Rendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.
727
+
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed URLs or [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/) in development.
728
+
In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution.
729
+
Rendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.
719
730
720
731
There are two possibilities to extract a style sheet from the bundle:
721
732
@@ -724,7 +735,8 @@ There are two possibilities to extract a style sheet from the bundle:
724
735
725
736
## Contributing
726
737
727
-
Please take a moment to read our contributing guidelines if you haven't yet done so.
738
+
We welcome all contributions!
739
+
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
0 commit comments