Skip to content

Commit

Permalink
docs: emit asset (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Aug 17, 2020
1 parent 53f678d commit 68699f6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,51 @@ module.exports = {
};
```

### `Emit assets`

To write a asset from the postcss plugin to the webpack's output file system, need to add a message in `result.messages`.
The message should contain the following fields:

- `type` = `asset` - Message type (require, should be equal `asset`)
- `file` - file name (require)
- `content` - file content (require)
- `sourceMap` - sourceMap
- `info` - asset info

**`webpack.config.js`**

```js
const customPlugin = () => (css, result) => {
result.messages.push({
type: 'asset',
file: 'sprite.svg',
content: '<svg>...</svg>',
});
};

const postcssPlugin = postcss.plugin('postcss-assets', customPlugin);

module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [postcssPlugin()],
},
},
],
},
],
},
};
```

<h2 align="center">Maintainers</h2>

<table>
Expand Down

0 comments on commit 68699f6

Please sign in to comment.