Skip to content

Commit

Permalink
Merge pull request #96 from nealgranger/master
Browse files Browse the repository at this point in the history
Allow control over loader `exec`.
  • Loading branch information
ai authored Sep 8, 2016
2 parents e3fb6d2 + 58949e4 commit 66770e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = function (source, map) {
}

var plugins;
var exec;
if ( typeof options === 'undefined' ) {
plugins = [];
} else if ( Array.isArray(options) ) {
Expand All @@ -52,6 +53,7 @@ module.exports = function (source, map) {
opts.stringifier = options.stringifier;
opts.parser = options.parser;
opts.syntax = options.syntax;
exec = options.exec;
}
if ( params.pack ) {
plugins = options[params.pack];
Expand All @@ -69,11 +71,14 @@ module.exports = function (source, map) {
if ( params.stringifier ) {
opts.stringifier = require(params.stringifier);
}
if ( params.exec ) {
exec = params.exec;
}

var loader = this;
var callback = this.async();

if ( params.parser === 'postcss-js' ) {
if ( params.parser === 'postcss-js' || exec ) {
source = this.exec(source, this.resource);
}

Expand Down
9 changes: 9 additions & 0 deletions test/cases/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var postcssJs = require('postcss-js');

var style = {
a: {
color: 'green'
}
};

module.exports = postcssJs.parse(style);
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ describe('postcss-loader', function () {
expect(css).to.eql('a {\n color: red\n}');
});

it('processes CSS with exec', function () {
var css = require('!raw-loader!' +
'../?exec!' +
'./cases/exec.js');
expect(css).to.eql('a {\n color: green\n}');
});

it('inlines map', function () {
var css = require('!raw-loader!../?sourceMap=inline!./cases/style.css');
expect(css).to.include('/*# sourceMappingURL=');
Expand Down

0 comments on commit 66770e5

Please sign in to comment.