index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. (function(){
  2. "use strict";
  3. var PluginError = require('plugin-error'),
  4. through = require('through2'),
  5. rtlcss = require('rtlcss'),
  6. configLoader = require('rtlcss/lib/config-loader'),
  7. applySourceMap = require('vinyl-sourcemaps-apply');
  8. module.exports = function (config) {
  9. return through.obj(function (file, enc, cb) {
  10. var result;
  11. if (file.isNull()) {
  12. this.push(file);
  13. return cb();
  14. }
  15. if (file.isStream()) {
  16. this.emit('error', new PluginError('gulp-rtlcss', 'Streaming not supported'));
  17. return cb();
  18. }
  19. if (!config) {
  20. config = configLoader.load(null, file.cwd);
  21. }
  22. result = rtlcss.configure(config).process(file.contents.toString(), {
  23. prev: file.sourceMap
  24. });
  25. file.contents = Buffer.from(result.css);
  26. if (file.map) {
  27. applySourceMap(file, result.map);
  28. }
  29. this.push(file);
  30. cb();
  31. });
  32. };
  33. })();