diff --git a/src/index.js b/src/index.js index f07f6e50..abab1581 100644 --- a/src/index.js +++ b/src/index.js @@ -191,9 +191,18 @@ export default async function loader(content, sourceMap, meta = {}) { this.emitWarning(new Warning(warning)); }); - messages.forEach((msg) => { - if (msg.type === 'dependency') { - this.addDependency(msg.file); + messages.forEach((message) => { + if (message.type === 'dependency') { + this.addDependency(message.file); + } + + if (message.type === 'asset' && message.content && message.file) { + this.emitFile( + message.file, + message.content, + message.sourceMap, + message.info + ); } }); diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 824b3eac..cc439f7f 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -16,6 +16,10 @@ SyntaxError exports[`loader should emit Syntax Error: warnings 1`] = `Array []`; +exports[`loader should emit asset: errors 1`] = `Array []`; + +exports[`loader should emit asset: warnings 1`] = `Array []`; + exports[`loader should emit warning: css 1`] = ` "a { color: black } " diff --git a/test/loader.test.js b/test/loader.test.js index 54c67984..bb5eef3d 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -55,4 +55,28 @@ describe('loader', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should emit asset', async () => { + const plugin = () => (css, result) => { + result.messages.push({ + type: 'asset', + file: 'sprite.svg', + content: '...', + plugin, + }); + }; + + const postcssPlugin = postcss.plugin('postcss-assets', plugin); + + const compiler = getCompiler('./css/index.js', { + plugins: [postcssPlugin()], + config: false, + }); + const stats = await compile(compiler); + + // eslint-disable-next-line no-underscore-dangle + expect(stats.compilation.assets['sprite.svg']).toBeDefined(); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); });