File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -816,6 +816,51 @@ module.exports = {
816816};
817817```
818818
819+ ### ` Emit assets `
820+
821+ To write a asset from the postcss plugin to the webpack's output file system, need to add a message in ` result.messages ` .
822+ The message should contain the following fields:
823+
824+ - ` type ` = ` asset ` - Message type (require, should be equal ` asset ` )
825+ - ` file ` - file name (require)
826+ - ` content ` - file content (require)
827+ - ` sourceMap ` - sourceMap
828+ - ` info ` - asset info
829+
830+ ** ` webpack.config.js ` **
831+
832+ ``` js
833+ const customPlugin = () => (css , result ) => {
834+ result .messages .push ({
835+ type: ' asset' ,
836+ file: ' sprite.svg' ,
837+ content: ' <svg>...</svg>' ,
838+ });
839+ };
840+
841+ const postcssPlugin = postcss .plugin (' postcss-assets' , customPlugin);
842+
843+ module .exports = {
844+ module: {
845+ rules: [
846+ {
847+ test: / \. css$ / i ,
848+ use: [
849+ ' style-loader' ,
850+ ' css-loader' ,
851+ {
852+ loader: ' postcss-loader' ,
853+ options: {
854+ plugins: [postcssPlugin ()],
855+ },
856+ },
857+ ],
858+ },
859+ ],
860+ },
861+ };
862+ ```
863+
819864<h2 align =" center " >Maintainers</h2 >
820865
821866<table >
You can’t perform that action at this time.
0 commit comments