Skip to content

Instantly share code, notes, and snippets.

@JulienPradet
Last active November 28, 2016 09:39
Show Gist options
  • Save JulienPradet/d37479e0b1f6b83bfa815b000574e648 to your computer and use it in GitHub Desktop.
Save JulienPradet/d37479e0b1f6b83bfa815b000574e648 to your computer and use it in GitHub Desktop.
Build a webpack bundle from a stream
import webpack from 'webpack'
import {Readable} from 'stream'
const entryStream = new Readable()
entryStream.push(`
import { configure } from '@kadira/storybook';
function loadStories() {
require('./story1.js');
require('./story2.js');
require('./story3.js');
}
configure(loadStories, module);
`)
entryStream.push(null)
var compiler = webpack(/* config */)
const bundleStream = compiler.transformStream(entryStream)
fs.writeFile('config.js', bundleStream)
@JulienPradet
Copy link
Author

For instance in react-storybook, the config.js file must require one by one each story.

In order to avoid doing so manually i'm preparing a tool that generates it according to conventions.
I could still save the generated config.js file and use the saved file as the entry. However it does not really feel node-y.

I was wondering if it was possible to do somehting like this with webpack. I haven't found anything about it yet.

I hope it's a bit clearer if I put it this way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment