Skip to content

Commit 85838b0

Browse files
committed
Feature: Customize Webpack HTML
This changeset adds options to entrypoints to support customized operation of the `HtmlWebpackPlugin`. See below for full changeset. Changes enclosed: - Add properties for `output`, `htmlPlugins`, and `htmlOptions` to `WebpackPluginEntryPoint` - Use new options from `Config.ts`, by merging them into their expected places Fixes and closes electron#2968.
1 parent 362099a commit 85838b0

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/plugin/webpack/src/Config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Configuration as RawWebpackConfiguration } from 'webpack';
1+
import { Configuration as RawWebpackConfiguration, Output as WebpackOutput, Plugin as WebpackPlugin } from 'webpack';
22
import WebpackDevServer from 'webpack-dev-server';
33
import { ConfigurationFactory as WebpackConfigurationFactory } from './WebpackConfig';
4+
import { HtmlWebpackPlugin } from 'html-webpack-plugin';
45

56
export interface WebpackPluginEntryPoint {
67
/**
@@ -48,6 +49,20 @@ export interface WebpackPluginEntryPoint {
4849
* for all entries.
4950
*/
5051
nodeIntegration?: boolean;
52+
/**
53+
* Custom options to merge into the configuration passed to `HtmlWebpackPlugin`.
54+
*/
55+
htmlOptions?: Partial<HtmlWebpackPlugin.Options>;
56+
/**
57+
* Plugins to include before `HtmlWebpackPlugin`; typically, HTML plugin add-ons will
58+
* need to be placed here.
59+
*/
60+
htmlPlugins?: WebpackPlugin[];
61+
/**
62+
* Additional options to merge into the Webpack `output` configuration for this entry-
63+
* point.
64+
*/
65+
output?: WebpackOutput;
5166
}
5267

5368
export interface WebpackPreloadEntryPoint {

packages/plugin/webpack/src/WebpackConfig.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,26 @@ export default class WebpackConfigGenerator {
194194
target: this.rendererTarget(entryPoint),
195195
devtool: this.rendererSourceMapOption,
196196
mode: this.mode,
197-
output: {
197+
output: Object.assign(entryPoint.output || {}, {
198198
path: path.resolve(this.webpackDir, 'renderer'),
199199
filename: '[name]/index.js',
200200
globalObject: 'self',
201201
...(this.isProd ? {} : { publicPath: '/' }),
202-
},
202+
}),
203203
node: {
204204
__dirname: false,
205205
__filename: false,
206206
},
207207
plugins: [
208+
...(entryPoint.htmlPlugins || []),
208209
...(entryPoint.html
209210
? [
210-
new HtmlWebpackPlugin({
211+
new HtmlWebpackPlugin(Object.assign({}, {
211212
title: entryPoint.name,
212213
template: entryPoint.html,
213214
filename: `${entryPoint.name}/index.html`,
214215
chunks: [entryPoint.name].concat(entryPoint.additionalChunks || []),
215-
}) as WebpackPluginInstance,
216+
}, entryPoint.htmlOptions || {})) as WebpackPluginInstance,
216217
]
217218
: []),
218219
new webpack.DefinePlugin(defines),

0 commit comments

Comments
 (0)