Skip to content

HtmlWebpackPlugin with different JSON locales (data not populating) #48

Answered by webdiscus
loudpose asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @loudpose,

I have the solution.

Please update the @webdiscus/pug-loader to the version 2.10.6.

When the same template filename is used to generate many static HTML files with different user data, then to the template filename must be added a unique query param, e.g. index.pug?en, index.pug?fr, ...

locales.forEach((locale) => {
	const { code, file } = locale;
	const data = getLocalesData(locale);
	console.log(code, ':', data);

	const htmlPlugin = new HtmlWebpackPlugin({
		template: path.resolve(__dirname, 'views', 'pages', 'home', 'index.pug') + `?lang=${code}`, // <=
		filename: `${code}/index.html`,
		data: data,
		cache: false,
	});
	allHtmlPlugins.push(htmlPlugin);
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@loudpose
Comment options

Answer selected by loudpose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants