Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This will create the normal `style.css` and an additionnal `style.rtl.css`.
```
new WebpackRTLPlugin({
filename: 'style.[contenthash].rtl.css',
suffix: false,
options: {},
plugins: [],
diffOnly: false,
Expand All @@ -56,6 +57,7 @@ new WebpackRTLPlugin({

* `filename` the filename of the result file. May contain `[contenthash]`. Default to `style.css`.
* `[contenthash]` a hash of the content of the extracted file
* `suffix` suffix added to the original base filename before the extension, if filename isn't provided. Default to `.rtl`.
* `options` Options given to `rtlcss`. See the [rtlcss documentation for available options](http://rtlcss.com/learn/usage-guide/options/).
* `plugins` RTLCSS plugins given to `rtlcss`. See the [rtlcss documentation for writing plugins](http://rtlcss.com/learn/extending-rtlcss/writing-a-plugin/). Default to `[]`.
* `diffOnly` If set to `true`, the stylesheet created will only contain the css that differs from the source stylesheet. Default to `false`.
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cssDiff from '@romainberger/css-diff'
import {forEachOfLimit} from 'async'
import cssnano from 'cssnano'

const WebpackRTLPlugin = function(options = {filename: false, options: {}, plugins: []}) {
const WebpackRTLPlugin = function(options = {filename: false, suffix: false, options: {}, plugins: []}) {
this.options = options
}

Expand All @@ -31,7 +31,9 @@ WebpackRTLPlugin.prototype.apply = function(compiler) {
}
}
else {
const newFilename = `${path.basename(asset, '.css')}.rtl`
const suffix = this.options.suffix || '.rtl'
const newFilename = `${path.basename(asset, '.css')}${suffix}`

filename = asset.replace(path.basename(asset, '.css'), newFilename)
}

Expand Down
39 changes: 39 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,45 @@ describe('Webpack RTL Plugin', () => {
})
})

describe('Suffix option', () => {
let rtlCssBundlePath
let cssPath = 'assets/css'

before(done => {
const config = {
...baseConfig,
output: {
path: path.resolve(__dirname, 'dist-path'),
filename: 'bundle.js',
},
plugins: [
new ExtractTextPlugin(path.join(cssPath, 'style.css')),
new WebpackRTLPlugin({
suffix: '-rtl'
}),
],
}

webpack(config, (err, stats) => {
if (err) {
return done(err)
}

if (stats.hasErrors()) {
return done(new Error(stats.toString()))
}

rtlCssBundlePath = path.join(__dirname, 'dist-path', cssPath, 'style-rtl.css')

done()
})
})

it('should create rtl css bundle with -rtl suffix', () => {
expect(fs.existsSync(rtlCssBundlePath)).to.be.true
})
})

describe('Rtlcss options', () => {
const rtlCssBundlePath = path.join(__dirname, 'dist-options/style.rtl.css')

Expand Down