-
-
Notifications
You must be signed in to change notification settings - Fork 209
Allow control over loader exec.
#96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
Hm. Adding a new option looks like a hack. Other developers with same issue could miss this option. Could you describe this issue, that you want to fix here? Maybe we will find some better way? |
|
It's useful to be able to conditionally load the required module with We will be able to do this: module.exports = {
module: {
loaders: [
{
test: /\.style.js$/,
loader: "style-loader!css-loader!postcss-loader"
}
]
},
postcss: function () {
return {
parser: require('postcss-js'),
exec: true,
};
}
}Or this: module.exports = {
module: {
loaders: [
{
test: /\.style.xyz$/,
loader: "style-loader!css-loader!postcss-loader?parser=custom-parser&exec"
}
]
},
} |
|
@ai Having the parser itself define the exec behaviour is also an option. In https://github.com/postcss/postcss-js/blob/master/index.js, for example: var postcssJs = {
objectify: require('./objectifier'),
parse: require('./parser'),
async: require('./async'),
sync: require('./sync'),
+ __webpackExec: true,
};
module.exports = postcssJs;And then in the loader: - if ( params.parser === 'postcss-js' || exec ) {
+ if ( opts.parser.__webpackExec ) {
source = this.exec(source, this.resource);
} |
|
Yeap, we could change API. |
|
I don’t like the Maybe we should add I would be happy to avoid changing |
|
/cc @izaakschroeder |
|
@ai What do you mean about " |
|
@nealgranger postcss: function () {
return {
parser: require('postcss-js'),
exec: true,
};
}Right now |
|
there's already a case for this: https://github.com/postcss/postcss-loader/blob/master/index.js#L59. The webpack config can be an array or an object with a |
|
Ouh, I forget about it :(. Sure, we could add But what if developer need |
|
@ai The loader query syntax is still supported of course. I'm currently doing something similar to this: loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
},
{
test: /\.css\.js$/,
loader: "style-loader!css-loader!postcss-loader?parser=custom-parser&exec"
}
] |
|
I am suggesting to remove Let’s introduce one way to load |
|
@ai The |
|
@ai Were you thinking of a separate parameter like |
|
I understand #86 better now, The solution would be to allow using plain old |
|
We would need a way to specify whether to use |
|
Sure, let’s use something like this instead: postcss: function () {
return {
parser: require('postcss-js'),
plugins: [require('autoprefixer')]
};
} |
|
Other question: how it will be changed in webpack 2 ;) |
|
..and have |
|
how does postcss: function () {
return {
parser: require('postcss-js'),
plugins: [require('autoprefixer')]
};
}trigger using |
|
Hm, mayb I miss the point. Could you repeat what is the problem? |
|
How does the loader know to call |
|
@nealgranger I mean what is the main problem? #86 was that |
|
I was wrong to say that this is a fix for #86 |
|
To solve #86, we would need to do something like: if ( params.parser === 'postcss-js') {
source = require(source);
}which would prevent any code in the source file from being processed with webpack, but at least it would work. |
|
OK. So why you need this PR? To run |
|
yup |
|
I'm currently doing: export const parse = (source) => postcssJs.parse(transformSource(source)));as a "custom" parser |
|
@ai It's getting used here https://github.com/webpack-config/webpack-config-postcss/compare/postcss-js?expand=1. |
|
Sure, let’s me finish with PostCSS 5.2 and I will return to this issue. |
|
I hadn't considered |
|
@ai Thanks for looking at this!! 😄 |
|
Sure, I agree that |
|
Please check docs 54a644e |
|
Released in 0.13. |
An
execflag can be provided to the loader query or webpack config. This instructs the loader to load the source usingexec. This enhances the previous behavior which was to check that the loader query parser was strictly equal topostcss-js.This fixes an issue where the
postcss-jsparser cannot be specified through the webpack postcss config option.This also enables parsers other than
postcss-jsto receive executed module results.