Skip to content

fix: types issues in config mutator #9177

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

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
10 changes: 5 additions & 5 deletions scopes/webpack/config-mutator/config-mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ export class WebpackConfigMutator {
if (htmlPlugins) {
// iterate over all html plugins and add the scripts to the html
htmlPlugins.forEach((htmlPlugin) => {
if (htmlPlugin.userOptions !== undefined) {
htmlPlugin.options.templateContent = htmlPlugin.userOptions.templateContent;
if (htmlPlugin.userOptions !== undefined && htmlPlugin.userOptions?.templateContent !== undefined) {
if (htmlPlugin.options) htmlPlugin.options.templateContent = htmlPlugin.userOptions.templateContent;
}

const htmlContent =
Expand All @@ -347,7 +347,7 @@ export class WebpackConfigMutator {

const newHtmlContent = inject(htmlContent, element);

htmlPlugin.options.templateContent = newHtmlContent;
if (htmlPlugin.options) htmlPlugin.options.templateContent = newHtmlContent;
htmlPlugin.userOptions.templateContent = newHtmlContent;
});
}
Expand Down Expand Up @@ -376,9 +376,9 @@ export class WebpackConfigMutator {
const htmlContent =
typeof htmlPlugin.options?.templateContent === 'function'
? htmlPlugin.options?.templateContent({})
: htmlPlugin.options.templateContent;
: htmlPlugin.options?.templateContent;

htmlPlugin.options.templateContent = (htmlContent as string).replace(element, '');
if (htmlPlugin.options) htmlPlugin.options.templateContent = (htmlContent as string).replace(element, '');

this.raw.plugins = this.raw.plugins.map((plugin) => {
if (plugin.constructor.name === 'HtmlWebpackPlugin') {
Expand Down