-
-
Notifications
You must be signed in to change notification settings - Fork 209
Closed
Description
I writing postcss plugin which produce extra asset (svg sprite) and need ability to write this asset to webpack's output file system. In 0.x versions of this loader it was feature when you can access loader object itself (webpack context property of postcss config). Using this, postcss plugins for instance can write assets directly to webpack compilation object, but it was removed. I suggest following:
- Postcss plugin generate message with new type "asset"
- If loader find such message it creates file in webpack compilation
Example
some-postcss-plugin.js
function plugin() {
return (tree, result) => {
// do stuff...
result.messages.push({
type: 'asset',
file: 'sprite.svg',
content: '<svg>...</svg>',
plugin
});
}
}postcss-loader
if (msg.type === 'asset' && msg.content && msg.file) {
this._compilation.assets[msg.file] = {
source() { return msg.content; },
size() { return msg.content.length; }
};
}I will be glad to make PR with this feature!
chookun