TIP
该配置由 Modern.js Builder 提供,更多信息可参考 tools.htmlPlugin。
false | Object | Function
const defaultHtmlPluginOptions = {
inject, // 对应 html.inject 配置项
favicon, // 对应 html.favicon 配置项
filename, // 基于 output.distPath 和 entryName 生成
template, // 默认为内置的 HTML 模板路径
templateParameters, // 对应 html.templateParameters 配置项
chunks: [entryName],
minify: {
removeComments: false,
useShortDoctype: true,
keepClosingSlash: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
},
};
通过 tools.htmlPlugin
可以修改 html-webpack-plugin 或 @rspack/plugin-html 的配置项。
当 tools.htmlPlugin
的值为 Object
类型时,会与默认配置通过 Object.assign
合并。
export default {
tools: {
htmlPlugin: {
scriptLoading: 'blocking',
},
},
};
当 tools.htmlPlugin
为 Function 类型时:
export default {
tools: {
htmlPlugin(config, { entryName, entryValue }) {
if (entryName === 'main') {
config.scriptLoading = 'blocking';
}
},
},
};
将 tools.htmlPlugin
配置为 false
,可以禁用默认的 html-webpack-plugin
插件。
export default {
tools: {
htmlPlugin: false,
},
};