Skip to content

Commit 9095c31

Browse files
committed
add sample postcss plugin
1 parent cbdf2d5 commit 9095c31

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
- edit `webpack-helpers/utils.js` (add `addRule` function)
2424
- add `webpack-helpers/sassPatch.js` and use it in `webpack.monkey.js`
2525
- add and use sample sass file
26+
- edit postcss configs
27+
- add package `yarn add postcss-inline-rtl`
28+
- edit `webpack-helpers/sassPatch.js`
29+
- add required changes in `src/index.js` and `sample.scss`
2630

2731
[monkey-react-scripts]: https://github.com/monkey-patches/monkey-react-scripts

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"babel-plugin-transform-decorators-legacy": "^1.3.4",
77
"monkey-react-scripts": "^0.1.0",
88
"node-sass": "^4.7.2",
9+
"postcss-inline-rtl": "^0.9.8",
910
"react": "^16.1.1",
1011
"react-dom": "^16.1.1",
1112
"react-scripts": "1.0.17",

Diff for: src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ import './index.css';
44
import App from './App';
55
import registerServiceWorker from './registerServiceWorker';
66

7+
const IS_RTL = true
8+
if (IS_RTL) {
9+
document.body.parentElement.dir = 'rtl'
10+
} else {
11+
document.body.parentElement.dir = 'ltr'
12+
}
13+
714
ReactDOM.render(<App />, document.getElementById('root'));
815
registerServiceWorker();

Diff for: src/sample.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ $color: lighten(red, 30%);
22

33
.red-bg {
44
background-color: $color;
5+
border-left: 4px solid red !important;
56
}

Diff for: webpack-helpers/sassPatch.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module.exports.sassPatch = function sassPatch (webpackConfig, isDevelopment) {
1010
const postCssLoader = cssLoaders[cssLoaders.length - 1]
1111
postCssLoader.options.sourceMap = true // add source option to postcss
1212

13+
// add rtl css support
14+
const postCssFunction = postCssLoader.options.plugins
15+
postCssLoader.options.plugins = () => {
16+
return [...postCssFunction(), require('postcss-inline-rtl')]
17+
}
18+
1319
// add sass support
1420
const sassLoader = {loader: require.resolve('sass-loader'), options: {sourceMap: true}}
1521
const sassLoaders = cssLoaders.concat(sassLoader)

Diff for: yarn.lock

+34-2
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,10 @@ colormin@^1.0.5:
14661466
css-color-names "0.0.4"
14671467
has "^1.0.1"
14681468

1469+
colors@~0.6.0-1:
1470+
version "0.6.2"
1471+
resolved "https://registry.yarnpkg.com/colors/-/colors-0.6.2.tgz#2423fe6678ac0c5dae8852e5d0e5be08c997abcc"
1472+
14691473
colors@~1.1.2:
14701474
version "1.1.2"
14711475
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
@@ -1484,6 +1488,10 @@ commander@^2.5.0, commander@^2.9.0:
14841488
version "2.12.1"
14851489
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.1.tgz#468635c4168d06145b9323356d1da84d14ac4a7a"
14861490

1491+
commander@~2.1.0:
1492+
version "2.1.0"
1493+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781"
1494+
14871495
commondir@^1.0.1:
14881496
version "1.0.1"
14891497
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
@@ -2687,6 +2695,13 @@ find-up@^2.0.0, find-up@^2.1.0:
26872695
dependencies:
26882696
locate-path "^2.0.0"
26892697

2698+
findup@^0.1.5:
2699+
version "0.1.5"
2700+
resolved "https://registry.yarnpkg.com/findup/-/findup-0.1.5.tgz#8ad929a3393bac627957a7e5de4623b06b0e2ceb"
2701+
dependencies:
2702+
colors "~0.6.0-1"
2703+
commander "~2.1.0"
2704+
26902705
flat-cache@^1.2.1:
26912706
version "1.3.0"
26922707
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.0.tgz#d3030b32b38154f4e3b7e9c709f490f7ef97c481"
@@ -5028,6 +5043,13 @@ [email protected]:
50285043
dependencies:
50295044
postcss "^6.0.1"
50305045

5046+
postcss-inline-rtl@^0.9.8:
5047+
version "0.9.8"
5048+
resolved "https://registry.yarnpkg.com/postcss-inline-rtl/-/postcss-inline-rtl-0.9.8.tgz#7c90317b7c6c0f6d12ac53cb0e5126c191ab05cb"
5049+
dependencies:
5050+
postcss "^6.0.1"
5051+
rtlcss "^2.0.3"
5052+
50315053
postcss-load-config@^1.2.0:
50325054
version "1.2.0"
50335055
resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-1.2.0.tgz#539e9afc9ddc8620121ebf9d8c3673e0ce50d28a"
@@ -5237,7 +5259,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
52375259
source-map "^0.5.6"
52385260
supports-color "^3.2.3"
52395261

5240-
postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.13:
5262+
postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.13, postcss@^6.0.14:
52415263
version "6.0.14"
52425264
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.14.tgz#5534c72114739e75d0afcf017db853099f562885"
52435265
dependencies:
@@ -5909,6 +5931,16 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
59095931
hash-base "^2.0.0"
59105932
inherits "^2.0.1"
59115933

5934+
rtlcss@^2.0.3:
5935+
version "2.2.1"
5936+
resolved "https://registry.yarnpkg.com/rtlcss/-/rtlcss-2.2.1.tgz#f8537e4155208166b05e189802131936fcefd29e"
5937+
dependencies:
5938+
chalk "^2.3.0"
5939+
findup "^0.1.5"
5940+
mkdirp "^0.5.1"
5941+
postcss "^6.0.14"
5942+
strip-json-comments "^2.0.0"
5943+
59125944
run-async@^2.2.0:
59135945
version "2.3.0"
59145946
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
@@ -6338,7 +6370,7 @@ strip-indent@^1.0.1:
63386370
dependencies:
63396371
get-stdin "^4.0.1"
63406372

6341-
strip-json-comments@~2.0.1:
6373+
strip-json-comments@^2.0.0, strip-json-comments@~2.0.1:
63426374
version "2.0.1"
63436375
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
63446376

0 commit comments

Comments
 (0)