adds composable HtmlRspackPlugin with Meteor support

This commit is contained in:
Nacho Codoñer
2025-08-18 20:50:45 +02:00
parent e9f922cb3b
commit 8402c02aa8
4 changed files with 32 additions and 20 deletions

View File

@@ -25,6 +25,12 @@ type MeteorEnv = Record<string, any> & {
isReactEnabled: boolean;
isBlazeEnabled: boolean;
isBlazeHotEnabled: boolean;
/**
* A function that creates an instance of HtmlRspackPlugin with default options.
* @param options - Optional configuration options that will be merged with defaults
* @returns An instance of HtmlRspackPlugin
*/
HtmlRspackPlugin: (options?: HtmlRspackPluginOptions) => HtmlRspackPlugin;
}
export type ConfigFactory = (

View File

@@ -1,12 +1,12 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.21",
"version": "0.0.22",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@meteorjs/rspack",
"version": "0.0.21",
"version": "0.0.22",
"license": "ISC",
"dependencies": {
"ignore-loader": "^0.1.2",

View File

@@ -1,6 +1,6 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.21",
"version": "0.0.22",
"description": "Configuration logic for using Rspack in Meteor projects",
"main": "index.js",
"type": "module",

View File

@@ -161,6 +161,28 @@ export default function (inMeteor = {}, argv = {}) {
const buildOutputDir = path.resolve(process.cwd(), buildContext, outputDir);
Meteor.buildOutputDir = buildOutputDir;
// Add HtmlRspackPlugin function to Meteor
Meteor.HtmlRspackPlugin = (options = {}) => {
return new HtmlRspackPlugin({
inject: false,
cache: true,
filename: `../${buildContext}/${outputDir}/index.html`,
templateContent: `
<head>
<% for tag in htmlRspackPlugin.tags.headTags { %>
<%= toHtml(tag) %>
<% } %>
</head>
<body>
<% for tag in htmlRspackPlugin.tags.bodyTags { %>
<%= toHtml(tag) %>
<% } %>
</body>
`,
...options
});
};
// Set watch options
const watchOptions = {
...defaultWatchOptions,
@@ -291,23 +313,7 @@ export default function (inMeteor = {}, argv = {}) {
banner: bannerOutput,
entryOnly: true,
}),
new HtmlRspackPlugin({
inject: false,
cache: true,
filename: `../${buildContext}/${outputDir}/index.html`,
templateContent: `
<head>
<% for tag in htmlRspackPlugin.tags.headTags { %>
<%= toHtml(tag) %>
<% } %>
</head>
<body>
<% for tag in htmlRspackPlugin.tags.bodyTags { %>
<%= toHtml(tag) %>
<% } %>
</body>
`,
}),
// Meteor.HtmlRspackPlugin(),
],
watchOptions,
devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',