Dеar wеbpack gurus.
Is there a way to bundle my project using webpack without writing output to a file, but rather get the resulting bundle module as a variable in my js scope?
Something like that would be perfect:
const webpack = require('webpack');
webpackConfig.outputFormat = 'localVariable';
const compiler = webpack(webpackConfig);
compiler.compileLocally((err, locallyBundledApp) => {
const methodResult = locallyBundledApp.someAppMethod();
console.log('app method result: ', methodResult);
});
I was looking for this in the docs, but the only compilation output available in js scope mentioned there was stats
.
My use case: I need to run a jest test that tests a code depending on a non-standard js flavour (PEG.js) scripts. There is a webpack loader for that, but without webpack this code can't be run - so I need to build the project bundle at the start of the test with webpack and then run my test assertions on the compiled bundle.
I can of course output to something like /tmp/ololo-bundle.js
and then do
const bundledApp = require('/tmp/ololo-bundle.js');
but is this really the only way? Can't writes to file system be avoided in a webpack build?