Skip to content

Commit 58949e4

Browse files
author
Neal Granger
committed
Allow control over loader exec.
An `exec` flag can be provided to the loader query or webpack config. This instructs the loader to load the source using `exec`. This enhances the previous behavior which was to check that the loader query parser was strictly equal to `postcss-js`. This fixes an issue where the `postcss-js` parser cannot be specified through the webpack postcss config option. This also enables parsers other than `postcss-js` to receive executed module results.
1 parent 4cd23e3 commit 58949e4

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
@@ -51,6 +51,7 @@ module.exports = function (source, map) {
5151
}
5252

5353
var plugins;
54+
var exec;
5455
if ( typeof options === 'undefined' ) {
5556
plugins = [];
5657
} else if ( Array.isArray(options) ) {
@@ -60,6 +61,7 @@ module.exports = function (source, map) {
6061
opts.stringifier = options.stringifier;
6162
opts.parser = options.parser;
6263
opts.syntax = options.syntax;
64+
exec = options.exec;
6365
}
6466
if ( params.pack ) {
6567
plugins = options[params.pack];
@@ -77,11 +79,14 @@ module.exports = function (source, map) {
7779
if ( params.stringifier ) {
7880
opts.stringifier = require(params.stringifier);
7981
}
82+
if ( params.exec ) {
83+
exec = params.exec;
84+
}
8085

8186
var loader = this;
8287
var callback = this.async();
8388

84-
if ( params.parser === 'postcss-js' ) {
89+
if ( params.parser === 'postcss-js' || exec ) {
8590
source = this.exec(source, this.resource);
8691
}
8792

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)