@meteorjs/rspack 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +19 -0
- package/index.js +4 -0
- package/package.json +1 -1
- package/plugins/HtmlRspackPlugin.js +28 -0
- package/plugins/RspackMeteorHtmlPlugin.js +1 -1
- package/rspack.config.js +25 -20
package/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
defineConfig as _rspackDefineConfig,
|
|
6
6
|
Configuration as _RspackConfig,
|
|
7
7
|
} from '@rspack/cli';
|
|
8
|
+
import { HtmlRspackPluginOptions } from '@rspack/core';
|
|
8
9
|
|
|
9
10
|
export interface MeteorRspackConfig extends _RspackConfig {
|
|
10
11
|
meteor?: {
|
|
@@ -24,6 +25,12 @@ type MeteorEnv = Record<string, any> & {
|
|
|
24
25
|
isReactEnabled: boolean;
|
|
25
26
|
isBlazeEnabled: boolean;
|
|
26
27
|
isBlazeHotEnabled: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A function that creates an instance of HtmlRspackPlugin with default options.
|
|
30
|
+
* @param options - Optional configuration options that will be merged with defaults
|
|
31
|
+
* @returns An instance of HtmlRspackPlugin
|
|
32
|
+
*/
|
|
33
|
+
HtmlRspackPlugin: (options?: HtmlRspackPluginOptions) => HtmlRspackPlugin;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export type ConfigFactory = (
|
|
@@ -34,3 +41,15 @@ export type ConfigFactory = (
|
|
|
34
41
|
export function defineConfig(
|
|
35
42
|
factory: ConfigFactory
|
|
36
43
|
): ReturnType<typeof _rspackDefineConfig>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A plugin that composes the original HtmlRspackPlugin from @rspack/core
|
|
47
|
+
* and RspackMeteorHtmlPlugin, in that order.
|
|
48
|
+
*/
|
|
49
|
+
export class HtmlRspackPlugin {
|
|
50
|
+
constructor(options?: HtmlRspackPluginOptions);
|
|
51
|
+
apply(compiler: any): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Re-export HtmlRspackPluginOptions from @rspack/cli
|
|
55
|
+
export { HtmlRspackPluginOptions };
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineConfig as rspackDefineConfig } from '@rspack/cli';
|
|
2
|
+
import HtmlRspackPlugin from './plugins/HtmlRspackPlugin.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @typedef {import('rspack').Configuration & {
|
|
@@ -21,3 +22,6 @@ export function defineConfig(factory) {
|
|
|
21
22
|
|
|
22
23
|
// Export our helper plus passthrough
|
|
23
24
|
export default defineConfig;
|
|
25
|
+
|
|
26
|
+
// Export the HtmlRspackPlugin
|
|
27
|
+
export { HtmlRspackPlugin };
|
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import RspackMeteorHtmlPlugin, { loadHtmlRspackPluginFromHost } from './RspackMeteorHtmlPlugin.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plugin that composes the original HtmlRspackPlugin from @rspack/core
|
|
5
|
+
* and RspackMeteorHtmlPlugin, in that order.
|
|
6
|
+
*/
|
|
7
|
+
export default class HtmlRspackPlugin {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
apply(compiler) {
|
|
13
|
+
// Load the original HtmlRspackPlugin from the host project
|
|
14
|
+
const OriginalHtmlRspackPlugin = loadHtmlRspackPluginFromHost(compiler);
|
|
15
|
+
|
|
16
|
+
if (!OriginalHtmlRspackPlugin) {
|
|
17
|
+
throw new Error('Could not load HtmlRspackPlugin from host project.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Apply the original HtmlRspackPlugin
|
|
21
|
+
const originalPlugin = new OriginalHtmlRspackPlugin(this.options);
|
|
22
|
+
originalPlugin.apply(compiler);
|
|
23
|
+
|
|
24
|
+
// Apply the RspackMeteorHtmlPlugin
|
|
25
|
+
const meteorPlugin = new RspackMeteorHtmlPlugin();
|
|
26
|
+
meteorPlugin.apply(compiler);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
|
|
4
|
-
function loadHtmlRspackPluginFromHost(compiler) {
|
|
4
|
+
export function loadHtmlRspackPluginFromHost(compiler) {
|
|
5
5
|
// Prefer the compiler's context; fall back to process.cwd()
|
|
6
6
|
const ctx = compiler.options?.context || compiler.context || process.cwd();
|
|
7
7
|
const requireFromHost = createRequire(path.join(ctx, 'package.json'));
|
package/rspack.config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefinePlugin, BannerPlugin
|
|
1
|
+
import { DefinePlugin, BannerPlugin } from '@rspack/core';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import path from 'path';
|
|
@@ -9,7 +9,7 @@ import { RequireExternalsPlugin } from './plugins/RequireExtenalsPlugin.js';
|
|
|
9
9
|
import { getMeteorAppSwcConfig } from "./lib/swc.js";
|
|
10
10
|
import { mergeSplitOverlap } from './lib/mergeRulesSplitOverlap.js';
|
|
11
11
|
import CleanBuildAssetsPlugin from "./plugins/CleanBuildAssetsPlugin.js";
|
|
12
|
-
import
|
|
12
|
+
import HtmlRspackPlugin from './plugins/HtmlRspackPlugin.js';
|
|
13
13
|
|
|
14
14
|
const require = createRequire(import.meta.url);
|
|
15
15
|
|
|
@@ -161,6 +161,28 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
161
161
|
const buildOutputDir = path.resolve(process.cwd(), buildContext, outputDir);
|
|
162
162
|
Meteor.buildOutputDir = buildOutputDir;
|
|
163
163
|
|
|
164
|
+
// Add HtmlRspackPlugin function to Meteor
|
|
165
|
+
Meteor.HtmlRspackPlugin = (options = {}) => {
|
|
166
|
+
return new HtmlRspackPlugin({
|
|
167
|
+
inject: false,
|
|
168
|
+
cache: true,
|
|
169
|
+
filename: `../${buildContext}/${outputDir}/index.html`,
|
|
170
|
+
templateContent: `
|
|
171
|
+
<head>
|
|
172
|
+
<% for tag in htmlRspackPlugin.tags.headTags { %>
|
|
173
|
+
<%= toHtml(tag) %>
|
|
174
|
+
<% } %>
|
|
175
|
+
</head>
|
|
176
|
+
<body>
|
|
177
|
+
<% for tag in htmlRspackPlugin.tags.bodyTags { %>
|
|
178
|
+
<%= toHtml(tag) %>
|
|
179
|
+
<% } %>
|
|
180
|
+
</body>
|
|
181
|
+
`,
|
|
182
|
+
...options
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
164
186
|
// Set watch options
|
|
165
187
|
const watchOptions = {
|
|
166
188
|
...defaultWatchOptions,
|
|
@@ -291,24 +313,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
291
313
|
banner: bannerOutput,
|
|
292
314
|
entryOnly: true,
|
|
293
315
|
}),
|
|
294
|
-
|
|
295
|
-
inject: false,
|
|
296
|
-
cache: true,
|
|
297
|
-
filename: `../${buildContext}/${outputDir}/index.html`,
|
|
298
|
-
templateContent: `
|
|
299
|
-
<head>
|
|
300
|
-
<% for tag in htmlRspackPlugin.tags.headTags { %>
|
|
301
|
-
<%= toHtml(tag) %>
|
|
302
|
-
<% } %>
|
|
303
|
-
</head>
|
|
304
|
-
<body>
|
|
305
|
-
<% for tag in htmlRspackPlugin.tags.bodyTags { %>
|
|
306
|
-
<%= toHtml(tag) %>
|
|
307
|
-
<% } %>
|
|
308
|
-
</body>
|
|
309
|
-
`,
|
|
310
|
-
}),
|
|
311
|
-
new RspackMeteorHtmlPlugin(),
|
|
316
|
+
Meteor.HtmlRspackPlugin(),
|
|
312
317
|
],
|
|
313
318
|
watchOptions,
|
|
314
319
|
devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',
|