From 19f91e6177209ffca462fd73853252fc5c70938c Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:05:00 +0000 Subject: [PATCH 01/10] Convert to RTL --- lib/loader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/loader.js b/lib/loader.js index 7574ba15..f73d7053 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -8,6 +8,7 @@ var processCss = require("./processCss"); var getImportPrefix = require("./getImportPrefix"); var compileExports = require("./compile-exports"); +var rtlcss = require('rtlcss'); module.exports = function(content, map) { if(this.cacheable) this.cacheable(); @@ -31,7 +32,7 @@ module.exports = function(content, map) { }, function(err, result) { if(err) return callback(err); - var cssAsString = JSON.stringify(result.source); + var cssAsString = JSON.stringify(rtlcss.process(result.source)); // for importing CSS var importUrlPrefix = getImportPrefix(this, query); From ccbcdc71329453ca175ffa8e479a3be1b833ec9f Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:12:37 +0000 Subject: [PATCH 02/10] Add rtlcss package --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5523d83c..291e6e68 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "postcss-modules-local-by-default": "^1.0.1", "postcss-modules-scope": "^1.0.0", "postcss-modules-values": "^1.1.0", - "source-list-map": "^0.1.7" + "source-list-map": "^0.1.7", + "rtlcss": "^2.0.2" }, "devDependencies": { "codecov.io": "^0.1.2", From 27d1c94c4a72c7d0d35bdc8067179be2fbb3eaad Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:14:53 +0000 Subject: [PATCH 03/10] Update package.json --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 291e6e68..f49e94ab 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "css-loader", - "version": "0.26.1", - "author": "Tobias Koppers @sokra", - "description": "css loader module for webpack", + "name": "rtlcss-loader", + "version": "1.0.0", + "author": "Sidati MESSAITI", + "description": "rtlcss loader module for webpack based on github.com/webpack/css-loader", "engines": { "node": ">=0.12.0" }, @@ -37,7 +37,7 @@ }, "repository": { "type": "git", - "url": "git@github.com:webpack/css-loader.git" + "url": "git@github.com:sidati/rtlcss-loader.git" }, "license": "MIT" } From a32e46151987bf90bcc09b9085997243295cd6f0 Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:37:31 +0000 Subject: [PATCH 04/10] Update README.md --- README.md | 278 ++++++------------------------------------------------ 1 file changed, 28 insertions(+), 250 deletions(-) diff --git a/README.md b/README.md index 55674fc6..bb8cd90e 100644 --- a/README.md +++ b/README.md @@ -1,278 +1,56 @@ -# css loader for webpack +# rtlcss loader for webpack +Work just like **[css-loader](https://github.com/webpack/css-loader)** and use **[rtlcss](https://github.com/MohammadYounes/rtlcss/)** to RTLify your css. ## installation -`npm install css-loader --save-dev` +`npm install https://github.com/sidati/rtlcss-loader/tarball/v1.0.0 --save-dev` ## Usage [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) -``` javascript -var css = require("css-loader!./file.css"); -// => returns css code from file.css, resolves imports and url(...) -``` - -`@import` and `url(...)` are interpreted like `require()` and will be resolved by the css-loader. -Good loaders for requiring your assets are the [file-loader](https://github.com/webpack/file-loader) -and the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see below). - -To be compatible with existing css files (if not in CSS Module mode): -* `url(image.png)` => `require("./image.png")` -* `url(~module/image.png)` => `require("module/image.png")` - -### Example config - -This webpack config can load css files, embed small png images as Data Urls and jpg images as files. - ``` javascript module.exports = { module: { loaders: [ - { test: /\.css$/, loader: "style-loader!css-loader" }, - { test: /\.png$/, loader: "url-loader?limit=100000" }, - { test: /\.jpg$/, loader: "file-loader" } + { + test: /\.css$/, + loaders: ['style', 'rtlcss'] + } ] } }; ``` -### 'Root-relative' urls - -For urls that start with a `/`, the default behavior is to not translate them: -* `url(/image.png)` => `url(/image.png)` - -If a `root` query parameter is set, however, it will be prepended to the url -and then translated: - -With a config like: - -``` javascript - loaders: [ - { test: /\.css$/, loader: "style-loader!css-loader?root=." }, - ... - ] -``` - -The result is: - -* `url(/image.png)` => `require("./image.png")` - -Using 'Root-relative' urls is not recommended. You should only use it for legacy CSS files. - -### Local scope - -By default CSS exports all class names into a global selector scope. Styles can be locally scoped to avoid globally scoping styles. - -The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module. - -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. - -The loader replaces local selectors with unique identifiers. The choosen unique identifiers are exported by the module. - -Example: - -``` css -:local(.className) { background: red; } -:local .className { color: green; } -:local(.className .subClass) { color: green; } -:local .className .subClass :global(.global-class-name) { color: blue; } -``` - -is transformed to - -``` css -._23_aKvs-b8bW2Vg3fwHozO { background: red; } -._23_aKvs-b8bW2Vg3fwHozO { color: green; } -._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 { color: green; } -._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 .global-class-name { color: blue; } -``` - -and the identifiers are exported: - -``` js -exports.locals = { - className: "_23_aKvs-b8bW2Vg3fwHozO", - subClass: "_13LGdX8RMStbBE9w-t0gZ1" -} -``` - -Camelcasing is recommended for local selectors. They are easier to use in the importing javascript module. - -`url(...)` URLs in block scoped (`:local .abc`) rules behave like requests in modules: - * `./file.png` instead of `file.png` - * `module/file.png` instead of `~module/file.png` - - -You can use `:local(#someId)`, but this is not recommended. Use classes instead of ids. - -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. - -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: - -```js -{ - test: /\.css$/, +for SASS/LESS you'll need **[sass-loader](https://github.com/jtangelder/sass-loader)** first : +```javascript +module.exports = { + module: { loaders: [ - { - loader: 'css-loader', - query: { - modules: true, - importLoaders: 1, - getLocalIdent: function (loaderContext, localIdentName, localName, options) { - return 'whatever_random_class_name' - } - } - } + { + test: /\.css$/, + loaders: ['style', 'rtlcss', 'sass'] + } ] -}, -``` - - -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. - -### CSS Modules - -See [CSS Modules](https://github.com/css-modules/css-modules). - -The query parameter `modules` enables the **CSS Modules** spec. (`css-loader?modules`) - -This enables Local scoped CSS by default. (You can switch it off with `:global(...)` or `:global` for selectors and/or rules.) - -### Composing CSS classes - -When declaring a local class name you can compose a local class from another local class name. - -``` css -:local(.className) { - background: red; - color: yellow; -} - -:local(.subClass) { - composes: className; - background: blue; -} -``` - -This doesn't result in any change to the CSS itself but exports multiple class names: - -``` js -exports.locals = { - className: "_23_aKvs-b8bW2Vg3fwHozO", - subClass: "_13LGdX8RMStbBE9w-t0gZ1 _23_aKvs-b8bW2Vg3fwHozO" -} -``` - -and CSS is transformed to: - -``` css -._23_aKvs-b8bW2Vg3fwHozO { - background: red; - color: yellow; -} - -._13LGdX8RMStbBE9w-t0gZ1 { - background: blue; -} -``` - -### Importing local class names - -To import a local class name from another module: - -``` css -:local(.continueButton) { - composes: button from "library/button.css"; - background: red; -} -``` - -``` css -:local(.nameEdit) { - composes: edit highlight from "./edit.css"; - background: red; -} + } +}; ``` -To import from multiple modules use multiple `composes:` rules. +## IMPORTANT -``` css -:local(.className) { - composes: edit hightlight from "./edit.css"; - composes: button from "module/button.css"; - composes: classFromThisModule; - background: red; +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 : +```css +div { + /*rtl:ignore*/ + margin: -25px -25px 0 0; } ``` - -### SourceMaps - -To include SourceMaps set the `sourceMap` query param. - -`require("css-loader?sourceMap!./file.css")` - -I. e. the extract-text-webpack-plugin can handle them. - -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. - -### importing and chained loaders - -The query parameter `importLoaders` allow to configure which loaders should be applied to `@import`ed resources. - -`importLoaders` (int): That many loaders after the css-loader are used to import resources. - -Examples: - -``` js -require("style-loader!css-loader?importLoaders=1!postcss-loader!...") -// => imported resources are handled this way: -require("css-loader?importLoaders=1!postcss-loader!...") - -require("style-loader!css-loader!stylus-loader!...") -// => imported resources are handled this way: -require("css-loader!...") -``` - -This may change in the future, when the module system (i. e. webpack) supports loader matching by origin. - -### Minification - -By default the css-loader minimizes the css if specified by the module system. - -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. - -You can also disable or enforce minification with the `minimize` query parameter. - -`require("css-loader?minimize!./file.css")` (enforced) - -`require("css-loader?-minimize!./file.css")` (disabled) - -### Disable behavior - -`css-loader?-url` disables `url(...)` handling. - -`css-loader?-import` disables `@import` handling. - -### Camel case - -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. - -Example: - -`css-loader?camelCase` - -Usage: +must be : ```css -/* file.css */ - -.class-name { /* ... */ } -``` - -```js -// javascript - -require('file.css').className +div { + /*!rtl:ignore*/ + margin: -25px -25px 0 0; +} ``` ## License From 3fa77207878c3941b971ced187b0d06739ec00ec Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:48:42 +0000 Subject: [PATCH 05/10] Update NPM install url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb8cd90e..deeb33ff 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Work just like **[css-loader](https://github.com/webpack/css-loader)** and use * ## installation -`npm install https://github.com/sidati/rtlcss-loader/tarball/v1.0.0 --save-dev` +`npm install rtlcss-loader --savde-dev` ## Usage From 84d4997faea635c94dd5d590e6d80497e5a1e5cd Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 9 Jan 2017 23:50:27 +0000 Subject: [PATCH 06/10] Version 1.01 --- .gitignore | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3091757a..193ad779 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -coverage \ No newline at end of file +coverage +*.log \ No newline at end of file diff --git a/package.json b/package.json index f49e94ab..3b6cf679 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rtlcss-loader", - "version": "1.0.0", + "version": "1.0.1", "author": "Sidati MESSAITI", "description": "rtlcss loader module for webpack based on github.com/webpack/css-loader", "engines": { From f2d0e7d6d6c06b935db8e26d687b63dba5d46adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B3=DB=8C=D8=AF=20=D9=85=D8=B1=D8=AA=D8=B6=DB=8C=20?= =?UTF-8?q?=D9=85=D9=88=D8=B3=D9=88=DB=8C?= Date: Sun, 22 Jan 2017 23:10:45 +0330 Subject: [PATCH 07/10] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index deeb33ff..4484d421 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ module.exports = { module: { loaders: [ { - test: /\.css$/, + test: /\.scss$/, loaders: ['style', 'rtlcss', 'sass'] } ] From e69781d3f248475d5edb19aacf8b89a59d2d43d7 Mon Sep 17 00:00:00 2001 From: Sidati MESSAITI Date: Mon, 6 Feb 2017 19:44:17 +0000 Subject: [PATCH 08/10] version 1.0.2 Fix typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3b6cf679..fa81a163 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rtlcss-loader", - "version": "1.0.1", + "version": "1.0.2", "author": "Sidati MESSAITI", "description": "rtlcss loader module for webpack based on github.com/webpack/css-loader", "engines": { From 5c0a4d74c57862b1c5ba6f913808616a17f6adbe Mon Sep 17 00:00:00 2001 From: Jacob Juul Christiansen Date: Thu, 28 Dec 2017 13:48:08 +0900 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4484d421..50ba4741 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Work just like **[css-loader](https://github.com/webpack/css-loader)** and use * ## installation -`npm install rtlcss-loader --savde-dev` +`npm install rtlcss-loader --save-dev` ## Usage From fbb5766e5a449cd4b1203e8baa7ea0043d1d3cb5 Mon Sep 17 00:00:00 2001 From: sidati Date: Sun, 26 May 2019 23:35:03 +0000 Subject: [PATCH 10/10] Fix a typo --- README.md | 15 +++++++++++---- package.json | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 50ba4741..acbbf41e 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ # rtlcss loader for webpack + Work just like **[css-loader](https://github.com/webpack/css-loader)** and use **[rtlcss](https://github.com/MohammadYounes/rtlcss/)** to RTLify your css. ## installation -`npm install rtlcss-loader --save-dev` +`npm i rtlcss-loader -D` ## Usage [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html) -``` javascript +```javascript module.exports = { module: { loaders: [ @@ -23,6 +24,7 @@ module.exports = { ``` for SASS/LESS you'll need **[sass-loader](https://github.com/jtangelder/sass-loader)** first : + ```javascript module.exports = { module: { @@ -38,14 +40,19 @@ module.exports = { ## IMPORTANT -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 : +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 : + ```css div { /*rtl:ignore*/ margin: -25px -25px 0 0; } ``` -must be : + +✔ must be : + ```css div { /*!rtl:ignore*/ diff --git a/package.json b/package.json index fa81a163..dba0f827 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,16 @@ { "name": "rtlcss-loader", - "version": "1.0.2", + "version": "1.0.3", "author": "Sidati MESSAITI", "description": "rtlcss loader module for webpack based on github.com/webpack/css-loader", "engines": { "node": ">=0.12.0" }, - "files": ["index.js", "locals.js", "lib"], + "files": [ + "index.js", + "locals.js", + "lib" + ], "dependencies": { "babel-code-frame": "^6.11.0", "css-selector-tokenizer": "^0.7.0", @@ -40,4 +44,4 @@ "url": "git@github.com:sidati/rtlcss-loader.git" }, "license": "MIT" -} +} \ No newline at end of file