Skip to content

Commit a32e461

Browse files
authored
Update README.md
1 parent 27d1c94 commit a32e461

File tree

1 file changed

+28
-250
lines changed

1 file changed

+28
-250
lines changed

README.md

+28-250
Original file line numberDiff line numberDiff line change
@@ -1,278 +1,56 @@
1-
# css loader for webpack
1+
# rtlcss loader for webpack
2+
Work just like **[css-loader](https://github.com/webpack/css-loader)** and use **[rtlcss](https://github.com/MohammadYounes/rtlcss/)** to RTLify your css.
23

34
## installation
45

5-
`npm install css-loader --save-dev`
6+
`npm install https://github.com/sidati/rtlcss-loader/tarball/v1.0.0 --save-dev`
67

78
## Usage
89

910
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
1011

11-
``` javascript
12-
var css = require("css-loader!./file.css");
13-
// => returns css code from file.css, resolves imports and url(...)
14-
```
15-
16-
`@import` and `url(...)` are interpreted like `require()` and will be resolved by the css-loader.
17-
Good loaders for requiring your assets are the [file-loader](https://github.com/webpack/file-loader)
18-
and the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see below).
19-
20-
To be compatible with existing css files (if not in CSS Module mode):
21-
* `url(image.png)` => `require("./image.png")`
22-
* `url(~module/image.png)` => `require("module/image.png")`
23-
24-
### Example config
25-
26-
This webpack config can load css files, embed small png images as Data Urls and jpg images as files.
27-
2812
``` javascript
2913
module.exports = {
3014
module: {
3115
loaders: [
32-
{ test: /\.css$/, loader: "style-loader!css-loader" },
33-
{ test: /\.png$/, loader: "url-loader?limit=100000" },
34-
{ test: /\.jpg$/, loader: "file-loader" }
16+
{
17+
test: /\.css$/,
18+
loaders: ['style', 'rtlcss']
19+
}
3520
]
3621
}
3722
};
3823
```
3924

40-
### 'Root-relative' urls
41-
42-
For urls that start with a `/`, the default behavior is to not translate them:
43-
* `url(/image.png)` => `url(/image.png)`
44-
45-
If a `root` query parameter is set, however, it will be prepended to the url
46-
and then translated:
47-
48-
With a config like:
49-
50-
``` javascript
51-
loaders: [
52-
{ test: /\.css$/, loader: "style-loader!css-loader?root=." },
53-
...
54-
]
55-
```
56-
57-
The result is:
58-
59-
* `url(/image.png)` => `require("./image.png")`
60-
61-
Using 'Root-relative' urls is not recommended. You should only use it for legacy CSS files.
62-
63-
### Local scope
64-
65-
By default CSS exports all class names into a global selector scope. Styles can be locally scoped to avoid globally scoping styles.
66-
67-
The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.
68-
69-
With `:local` (without brackets) local mode can be switched on for this selector. `:global(.className)` can be used to declare an explicit global selector. With `:global` (without brackets) global mode can be switched on for this selector.
70-
71-
The loader replaces local selectors with unique identifiers. The choosen unique identifiers are exported by the module.
72-
73-
Example:
74-
75-
``` css
76-
:local(.className) { background: red; }
77-
:local .className { color: green; }
78-
:local(.className .subClass) { color: green; }
79-
:local .className .subClass :global(.global-class-name) { color: blue; }
80-
```
81-
82-
is transformed to
83-
84-
``` css
85-
._23_aKvs-b8bW2Vg3fwHozO { background: red; }
86-
._23_aKvs-b8bW2Vg3fwHozO { color: green; }
87-
._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 { color: green; }
88-
._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 .global-class-name { color: blue; }
89-
```
90-
91-
and the identifiers are exported:
92-
93-
``` js
94-
exports.locals = {
95-
className: "_23_aKvs-b8bW2Vg3fwHozO",
96-
subClass: "_13LGdX8RMStbBE9w-t0gZ1"
97-
}
98-
```
99-
100-
Camelcasing is recommended for local selectors. They are easier to use in the importing javascript module.
101-
102-
`url(...)` URLs in block scoped (`:local .abc`) rules behave like requests in modules:
103-
* `./file.png` instead of `file.png`
104-
* `module/file.png` instead of `~module/file.png`
105-
106-
107-
You can use `:local(#someId)`, but this is not recommended. Use classes instead of ids.
108-
109-
You can configure the generated ident with the `localIdentName` query parameter (default `[hash:base64]`). Example: `css-loader?localIdentName=[path][name]---[local]---[hash:base64:5]` for easier debugging.
110-
111-
You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema. Note that this requires `webpack@2` since to be able to pass function in. For example:
112-
113-
```js
114-
{
115-
test: /\.css$/,
25+
for SASS/LESS you'll need **[sass-loader](https://github.com/jtangelder/sass-loader)** first :
26+
```javascript
27+
module.exports = {
28+
module: {
11629
loaders: [
117-
{
118-
loader: 'css-loader',
119-
query: {
120-
modules: true,
121-
importLoaders: 1,
122-
getLocalIdent: function (loaderContext, localIdentName, localName, options) {
123-
return 'whatever_random_class_name'
124-
}
125-
}
126-
}
30+
{
31+
test: /\.css$/,
32+
loaders: ['style', 'rtlcss', 'sass']
33+
}
12734
]
128-
},
129-
```
130-
131-
132-
Note: For prerendering with extract-text-webpack-plugin you should use `css-loader/locals` instead of `style-loader!css-loader` **in the prerendering bundle**. It doesn't embed CSS but only exports the identifier mappings.
133-
134-
### CSS Modules
135-
136-
See [CSS Modules](https://github.com/css-modules/css-modules).
137-
138-
The query parameter `modules` enables the **CSS Modules** spec. (`css-loader?modules`)
139-
140-
This enables Local scoped CSS by default. (You can switch it off with `:global(...)` or `:global` for selectors and/or rules.)
141-
142-
### Composing CSS classes
143-
144-
When declaring a local class name you can compose a local class from another local class name.
145-
146-
``` css
147-
:local(.className) {
148-
background: red;
149-
color: yellow;
150-
}
151-
152-
:local(.subClass) {
153-
composes: className;
154-
background: blue;
155-
}
156-
```
157-
158-
This doesn't result in any change to the CSS itself but exports multiple class names:
159-
160-
``` js
161-
exports.locals = {
162-
className: "_23_aKvs-b8bW2Vg3fwHozO",
163-
subClass: "_13LGdX8RMStbBE9w-t0gZ1 _23_aKvs-b8bW2Vg3fwHozO"
164-
}
165-
```
166-
167-
and CSS is transformed to:
168-
169-
``` css
170-
._23_aKvs-b8bW2Vg3fwHozO {
171-
background: red;
172-
color: yellow;
173-
}
174-
175-
._13LGdX8RMStbBE9w-t0gZ1 {
176-
background: blue;
177-
}
178-
```
179-
180-
### Importing local class names
181-
182-
To import a local class name from another module:
183-
184-
``` css
185-
:local(.continueButton) {
186-
composes: button from "library/button.css";
187-
background: red;
188-
}
189-
```
190-
191-
``` css
192-
:local(.nameEdit) {
193-
composes: edit highlight from "./edit.css";
194-
background: red;
195-
}
35+
}
36+
};
19637
```
19738

198-
To import from multiple modules use multiple `composes:` rules.
39+
## IMPORTANT
19940

200-
``` css
201-
:local(.className) {
202-
composes: edit hightlight from "./edit.css";
203-
composes: button from "module/button.css";
204-
composes: classFromThisModule;
205-
background: red;
41+
if you want to use [rtlcss directives](http://rtlcss.com/learn/usage-guide/control-directives/) such as `/*rtl:ignore*/` make sure you are using it as a SPECIAL comment by adding `!` before your comment, for example :
42+
```css
43+
div {
44+
/*rtl:ignore*/
45+
margin: -25px -25px 0 0;
20646
}
20747
```
208-
209-
### SourceMaps
210-
211-
To include SourceMaps set the `sourceMap` query param.
212-
213-
`require("css-loader?sourceMap!./file.css")`
214-
215-
I. e. the extract-text-webpack-plugin can handle them.
216-
217-
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS SourceMap do not). In addition to that relative paths are buggy and you need to use an absolute public path which include the server url.
218-
219-
### importing and chained loaders
220-
221-
The query parameter `importLoaders` allow to configure which loaders should be applied to `@import`ed resources.
222-
223-
`importLoaders` (int): That many loaders after the css-loader are used to import resources.
224-
225-
Examples:
226-
227-
``` js
228-
require("style-loader!css-loader?importLoaders=1!postcss-loader!...")
229-
// => imported resources are handled this way:
230-
require("css-loader?importLoaders=1!postcss-loader!...")
231-
232-
require("style-loader!css-loader!stylus-loader!...")
233-
// => imported resources are handled this way:
234-
require("css-loader!...")
235-
```
236-
237-
This may change in the future, when the module system (i. e. webpack) supports loader matching by origin.
238-
239-
### Minification
240-
241-
By default the css-loader minimizes the css if specified by the module system.
242-
243-
In some cases the minification is destructive to the css, so you can provide some options to it. cssnano is used for minification and you find a [list of options here](http://cssnano.co/options/). Just provide them as query parameter: i. e. `require("css-loader?-colormin")` to disable making color values as small as possible.
244-
245-
You can also disable or enforce minification with the `minimize` query parameter.
246-
247-
`require("css-loader?minimize!./file.css")` (enforced)
248-
249-
`require("css-loader?-minimize!./file.css")` (disabled)
250-
251-
### Disable behavior
252-
253-
`css-loader?-url` disables `url(...)` handling.
254-
255-
`css-loader?-import` disables `@import` handling.
256-
257-
### Camel case
258-
259-
By default, the exported JSON keys mirror the class names. If you want to camelize class names (useful in Javascript), pass the query parameter `camelCase` to the loader.
260-
261-
Example:
262-
263-
`css-loader?camelCase`
264-
265-
Usage:
48+
must be :
26649
```css
267-
/* file.css */
268-
269-
.class-name { /* ... */ }
270-
```
271-
272-
```js
273-
// javascript
274-
275-
require('file.css').className
50+
div {
51+
/*!rtl:ignore*/
52+
margin: -25px -25px 0 0;
53+
}
27654
```
27755

27856
## License

0 commit comments

Comments
 (0)