Skip to content
Merged
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
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.
  • Loading branch information
Neal Granger committed Sep 4, 2016
commit 58949e4a3b4a798c94ea11b281beb59f12074b12
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = function (source, map) {
}

var plugins;
var exec;
if ( typeof options === 'undefined' ) {
plugins = [];
} else if ( Array.isArray(options) ) {
Expand All @@ -60,6 +61,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 @@ -77,11 +79,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