From dfe78ef18c1ad95d9891ba07bafdd669c2564ca6 Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Sat, 22 Jul 2017 23:17:22 +0100 Subject: [PATCH 1/2] Add support for entry functions. --- index.js | 6 +++--- test/test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0cf2035..cc6f14a 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,9 @@ InertEntryPlugin.prototype.apply = function(compiler) { compilation.options.output.filename = placeholder; } - var entries = typeof compilation.options.entry === 'object' ? - compilation.options.entry : - { main: compilation.options.entry }; + var entries = compilation.options.entry; + if(typeof entries === 'function') entries = entries(); + if(typeof entries !== 'object') entries = { main: entries }; params.normalModuleFactory.plugin('after-resolve', function(data, callback) { // match the raw request to one of the entry files diff --git a/test/test.js b/test/test.js index 67953d5..18eaf91 100644 --- a/test/test.js +++ b/test/test.js @@ -92,6 +92,41 @@ test('multiple entry chunks', async t => { t.regex(appDistJs, /module\.exports = 'this should not be imported';/, 'has exports'); }); +test('single entry chunk though function', async t => { + const out = randomPath(); + + await new Promise((resolve, reject) => { + webpack({ + entry: () => join(__dirname, 'src/main.html'), + bail: true, + output: { + path: out, + filename: '[chunkname]-dist.html' + }, + module: { + loaders: [ + { test: /\.html$/, loaders: ['extricate-loader', 'html-loader?attrs=img:src script:src'] }, + { test: /\.js$/, loader: 'spawn-loader?name=[name]-dist.js' } + ] + }, + plugins: [ + new InertEntryPlugin() + ] + }, (err, stats) => { + err ? reject(err) : resolve(stats); + }); + }); + + const mainDistHtml = readFileSync(join(out, 'main-dist.html'), 'utf8'); + const appDistJs = readFileSync(join(out, 'app-dist.js'), 'utf8'); + + t.regex(mainDistHtml, /^/, 'no prelude'); + t.regex(mainDistHtml, /