Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for entry functions. #16

Merged
merged 2 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, /^<!DOCTYPE html>/, 'no prelude');
t.regex(mainDistHtml, /<script src="app-dist\.js"><\/script>/, 'references app-dist.js');

t.regex(appDistJs, /\bfunction __webpack_require__\b/, 'has prelude');
t.regex(appDistJs, /module\.exports = 'this should not be imported';/, 'has exports');
});

test('substituting [name] instead of [chunkname]', async t => {
const out = randomPath();

Expand Down