Skip to content

Commit

Permalink
fix: generate html files even if no webpack entry exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jan 20, 2021
1 parent 18bdd71 commit 2693dfa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class HtmlWebpackPlugin {
: (entryName) => userOptionFilename.replace(/\[name\]/g, entryName);

/** output filenames for the given entry names */
const outputFileNames = new Set(Object.keys(compiler.options.entry).map(filenameFunction));
const entryNames = Object.keys(compiler.options.entry);
const outputFileNames = new Set((entryNames.length ? entryNames : ['main']).map(filenameFunction));

/** Option for every entry point */
const entryOptions = Array.from(outputFileNames).map((filename) => ({
Expand Down
15 changes: 15 additions & 0 deletions spec/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2667,4 +2667,19 @@ describe('HtmlWebpackPlugin', () => {
]
}, ['<img src="/foo/assets/demo.png'], 'demo/index.js', done);
});

it('generates an html file if entry is empty', done => {
testHtmlPlugin({
mode: 'development',
entry: {},
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js',
assetModuleFilename: 'assets/demo[ext]'
},
plugins: [
new HtmlWebpackPlugin({})
]
}, ['<body>'], null, done);
});
});

0 comments on commit 2693dfa

Please sign in to comment.