A possible solution for the case of generating html by server (Node.js) in runtime, mentioned by @Jonik above.
For development:
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('../../internals/webpack/webpack.dev.babel');
const compiler = webpack(webpackConfig);
const middleware = webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath,
silent: true,
stats: 'errors-only',
});
const fileSystem = middleware.fileSystem;
const encoding = 'utf-8';
const outputPath = compiler.outputPath;
For production:
const fs = require('fs');
const path= require('path');
const fileSystem = fs;
const encoding = { encoding: 'utf-8' };
const outputPath = path.resolve(process.cwd(), 'build');
And then:
let style = '';
fileSystem.readdirSync(outputPath).forEach((file) => {
if (file.indexOf('.css') !== -1) {
style += fileSystem.readFileSync(`${outputPath}/${file}`, encoding);
}
});
The 'style' variable will contain your css bundled by ExtractTextPlugin.