How can I create a loader for webpack which exposes all sources via a function?

Viewed 184

I would like to have a loader that collects all css sources and allows me to get all contents in a function. Like this:

Webpack config

module: {
  loaders: [
    {test: /\.css$/, loader: 'my-loader'}
  ]
}

JS file A (foo.js)

import './foo.css';

JS file B (bar.js)

import './bar.css';

JS file C (app.js)

import './app.css';
import getAllCSSContents from 'my-loader';

const css = getAllCSSContents();

where getAllCSSContents would return all CSS contents from foo.css, bar.css and app.css

1 Answers
Related