Skip to content

Commit 66770e5

Browse files
authored
Merge pull request #96 from nealgranger/master
Allow control over loader `exec`.
2 parents e3fb6d2 + 58949e4 commit 66770e5

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = function (source, map) {
4343
}
4444

4545
var plugins;
46+
var exec;
4647
if ( typeof options === 'undefined' ) {
4748
plugins = [];
4849
} else if ( Array.isArray(options) ) {
@@ -52,6 +53,7 @@ module.exports = function (source, map) {
5253
opts.stringifier = options.stringifier;
5354
opts.parser = options.parser;
5455
opts.syntax = options.syntax;
56+
exec = options.exec;
5557
}
5658
if ( params.pack ) {
5759
plugins = options[params.pack];
@@ -69,11 +71,14 @@ module.exports = function (source, map) {
6971
if ( params.stringifier ) {
7072
opts.stringifier = require(params.stringifier);
7173
}
74+
if ( params.exec ) {
75+
exec = params.exec;
76+
}
7277

7378
var loader = this;
7479
var callback = this.async();
7580

76-
if ( params.parser === 'postcss-js' ) {
81+
if ( params.parser === 'postcss-js' || exec ) {
7782
source = this.exec(source, this.resource);
7883
}
7984

test/cases/exec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var postcssJs = require('postcss-js');
2+
3+
var style = {
4+
a: {
5+
color: 'green'
6+
}
7+
};
8+
9+
module.exports = postcssJs.parse(style);

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ describe('postcss-loader', function () {
3131
expect(css).to.eql('a {\n color: red\n}');
3232
});
3333

34+
it('processes CSS with exec', function () {
35+
var css = require('!raw-loader!' +
36+
'../?exec!' +
37+
'./cases/exec.js');
38+
expect(css).to.eql('a {\n color: green\n}');
39+
});
40+
3441
it('inlines map', function () {
3542
var css = require('!raw-loader!../?sourceMap=inline!./cases/style.css');
3643
expect(css).to.include('/*# sourceMappingURL=');

0 commit comments

Comments
 (0)