@meteorjs/rspack 0.0.45 → 0.0.47
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.js +8 -7
- package/lib/mergeRulesSplitOverlap.js +35 -6
- package/lib/swc.js +9 -4
- package/package.json +2 -2
- package/plugins/HtmlRspackPlugin.js +5 -2
- package/plugins/RequireExtenalsPlugin.js +5 -3
- package/plugins/RspackMeteorHtmlPlugin.js +7 -4
- package/rspack.config.js +11 -13
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { defineConfig: rspackDefineConfig } = require('@rspack/cli');
|
|
2
|
+
const HtmlRspackPlugin = require('./plugins/HtmlRspackPlugin.js');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import('rspack').Configuration & {
|
|
@@ -16,12 +16,13 @@ import HtmlRspackPlugin from './plugins/HtmlRspackPlugin.js';
|
|
|
16
16
|
* @param {ConfigFactory} factory
|
|
17
17
|
* @returns {ReturnType<typeof rspackDefineConfig>}
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
function defineConfig(factory) {
|
|
20
20
|
return rspackDefineConfig(factory);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
// Export our helper plus passthrough
|
|
24
|
-
|
|
23
|
+
// Export our helper plus passthrough as default export
|
|
24
|
+
module.exports = defineConfig;
|
|
25
25
|
|
|
26
|
-
// Export the HtmlRspackPlugin
|
|
27
|
-
|
|
26
|
+
// Export the HtmlRspackPlugin and defineConfig as named exports
|
|
27
|
+
module.exports.defineConfig = defineConfig;
|
|
28
|
+
module.exports.HtmlRspackPlugin = HtmlRspackPlugin;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* overlapping file extensions in module rules.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const { mergeWithCustomize } = require('webpack-merge');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* File extensions to check when determining rule overlaps.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
const EXT_CATALOG = [
|
|
12
12
|
'.tsx', '.ts', '.mts', '.cts',
|
|
13
13
|
'.jsx', '.js', '.mjs', '.cjs',
|
|
14
14
|
];
|
|
@@ -130,7 +130,7 @@ function splitOverlapRulesMerge(aRules, bRules) {
|
|
|
130
130
|
* @param {Function} getter - Function to get the identifier from the plugin
|
|
131
131
|
* @returns {Function} Customizer function
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
function unique(key, pluginNames = [], getter = item => item.constructor && item.constructor.name) {
|
|
134
134
|
return (a, b, k) => {
|
|
135
135
|
if (k !== key) return undefined;
|
|
136
136
|
|
|
@@ -183,7 +183,7 @@ export function unique(key, pluginNames = [], getter = item => item.constructor
|
|
|
183
183
|
* @param {Function} [options.warningFn] - Custom warning function that receives the path string
|
|
184
184
|
* @returns {Object} The cleaned object with specified paths removed
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
function cleanOmittedPaths(obj, options = {}) {
|
|
187
187
|
if (!obj || typeof obj !== 'object') {
|
|
188
188
|
return obj;
|
|
189
189
|
}
|
|
@@ -252,13 +252,35 @@ export function cleanOmittedPaths(obj, options = {}) {
|
|
|
252
252
|
return result;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Normalizes externals configuration to ensure consistent handling.
|
|
257
|
+
* @param {Object} config - The configuration object
|
|
258
|
+
* @returns {Object} - The normalized configuration
|
|
259
|
+
*/
|
|
260
|
+
function normalizeExternals(config) {
|
|
261
|
+
if (!config || !config.externals) return config;
|
|
262
|
+
|
|
263
|
+
// Create a deep clone of the config to avoid modifying the original
|
|
264
|
+
const result = { ...config };
|
|
265
|
+
|
|
266
|
+
// If externals is not an array, convert it to an array
|
|
267
|
+
if (!Array.isArray(result.externals)) {
|
|
268
|
+
result.externals = [result.externals];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
|
|
255
274
|
/**
|
|
256
275
|
* Merges webpack/rspack configs with smart handling of overlapping rules.
|
|
257
276
|
*
|
|
258
277
|
* @param {...Object} configs - Configs to merge
|
|
259
278
|
* @returns {Object} Merged config
|
|
260
279
|
*/
|
|
261
|
-
|
|
280
|
+
function mergeSplitOverlap(...configs) {
|
|
281
|
+
// Normalize externals in all configs before merging
|
|
282
|
+
const normalizedConfigs = configs.map(normalizeExternals);
|
|
283
|
+
|
|
262
284
|
return mergeWithCustomize({
|
|
263
285
|
customizeArray(a, b, key) {
|
|
264
286
|
if (key === 'module.rules') {
|
|
@@ -287,5 +309,12 @@ export function mergeSplitOverlap(...configs) {
|
|
|
287
309
|
// fall through to default merging
|
|
288
310
|
return undefined;
|
|
289
311
|
}
|
|
290
|
-
})(...
|
|
312
|
+
})(...normalizedConfigs);
|
|
291
313
|
}
|
|
314
|
+
|
|
315
|
+
module.exports = {
|
|
316
|
+
EXT_CATALOG,
|
|
317
|
+
unique,
|
|
318
|
+
cleanOmittedPaths,
|
|
319
|
+
mergeSplitOverlap
|
|
320
|
+
};
|
package/lib/swc.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const vm = require('vm');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Reads and parses the SWC configuration file.
|
|
6
6
|
* @param {string} file - The name of the SWC configuration file (default: '.swcrc')
|
|
7
7
|
* @returns {Object|undefined} The parsed SWC configuration or undefined if an error occurs
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
function getMeteorAppSwcrc(file = '.swcrc') {
|
|
10
10
|
try {
|
|
11
11
|
const filePath = `${process.cwd()}/${file}`;
|
|
12
12
|
if (file.endsWith('.js')) {
|
|
@@ -42,7 +42,7 @@ export function getMeteorAppSwcrc(file = '.swcrc') {
|
|
|
42
42
|
* If the configuration has a baseUrl property, it will be set to process.cwd().
|
|
43
43
|
* @returns {Object|undefined} The SWC configuration or undefined if no configuration exists
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
function getMeteorAppSwcConfig() {
|
|
46
46
|
const hasSwcRc = fs.existsSync(`${process.cwd()}/.swcrc`);
|
|
47
47
|
const hasSwcJs = !hasSwcRc && fs.existsSync(`${process.cwd()}/swc.config.js`);
|
|
48
48
|
|
|
@@ -60,3 +60,8 @@ export function getMeteorAppSwcConfig() {
|
|
|
60
60
|
|
|
61
61
|
return config;
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
getMeteorAppSwcrc,
|
|
66
|
+
getMeteorAppSwcConfig
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meteorjs/rspack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "Configuration logic for using Rspack in Meteor projects",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"type": "
|
|
6
|
+
"type": "commonjs",
|
|
7
7
|
"author": "",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"dependencies": {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const RspackMeteorHtmlPlugin = require('./RspackMeteorHtmlPlugin.js');
|
|
2
|
+
const { loadHtmlRspackPluginFromHost } = RspackMeteorHtmlPlugin;
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* A plugin that composes the original HtmlRspackPlugin from @rspack/core
|
|
5
6
|
* and RspackMeteorHtmlPlugin, in that order.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
class HtmlRspackPlugin {
|
|
8
9
|
constructor(options = {}) {
|
|
9
10
|
this.options = options;
|
|
10
11
|
}
|
|
@@ -26,3 +27,5 @@ export default class HtmlRspackPlugin {
|
|
|
26
27
|
meteorPlugin.apply(compiler);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
module.exports = HtmlRspackPlugin;
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
// the externalMap function if provided.
|
|
8
8
|
// Used for Blaze to translate require of html files to require of js files bundled by Meteor.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
class RequireExternalsPlugin {
|
|
14
14
|
constructor({
|
|
15
15
|
filePath,
|
|
16
16
|
// Externals can be:
|
|
@@ -487,3 +487,5 @@ export class RequireExternalsPlugin {
|
|
|
487
487
|
return existing;
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
|
+
|
|
491
|
+
module.exports = { RequireExternalsPlugin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const path = require('node:path');
|
|
2
|
+
const { createRequire } = require('node:module');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
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'));
|
|
@@ -16,7 +16,7 @@ export function loadHtmlRspackPluginFromHost(compiler) {
|
|
|
16
16
|
* 1. Remove the injected `*-rspack.js` script tags
|
|
17
17
|
* 2. Strip <!doctype> and <html>…</html> wrappers from the final HTML
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
class RspackMeteorHtmlPlugin {
|
|
20
20
|
apply(compiler) {
|
|
21
21
|
const HtmlRspackPlugin = loadHtmlRspackPluginFromHost(compiler);
|
|
22
22
|
if (!HtmlRspackPlugin?.getCompilationHooks) {
|
|
@@ -45,3 +45,6 @@ export default class RspackMeteorHtmlPlugin {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
module.exports = RspackMeteorHtmlPlugin;
|
|
50
|
+
module.exports.loadHtmlRspackPluginFromHost = loadHtmlRspackPluginFromHost;
|
package/rspack.config.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { merge } from 'webpack-merge';
|
|
1
|
+
const { DefinePlugin, BannerPlugin } = require('@rspack/core');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { inspect } = require('node:util');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { merge } = require('webpack-merge');
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
7
|
+
const { cleanOmittedPaths, mergeSplitOverlap } = require("./lib/mergeRulesSplitOverlap.js");
|
|
8
|
+
const { getMeteorAppSwcConfig } = require('./lib/swc.js');
|
|
9
|
+
const HtmlRspackPlugin = require('./plugins/HtmlRspackPlugin.js');
|
|
10
|
+
const { RequireExternalsPlugin } = require('./plugins/RequireExtenalsPlugin.js');
|
|
14
11
|
|
|
15
12
|
// Safe require that doesn't throw if the module isn't found
|
|
16
13
|
function safeRequire(moduleName) {
|
|
@@ -114,7 +111,7 @@ const defaultWatchOptions = {
|
|
|
114
111
|
* @param {{ mode?: string; clientEntry?: string; serverEntry?: string; clientOutputFolder?: string; serverOutputFolder?: string; chunksContext?: string; assetsContext?: string; serverAssetsContext?: string }} argv
|
|
115
112
|
* @returns {import('@rspack/cli').Configuration[]}
|
|
116
113
|
*/
|
|
117
|
-
|
|
114
|
+
module.exports = function (inMeteor = {}, argv = {}) {
|
|
118
115
|
// Transform Meteor env properties to proper boolean values
|
|
119
116
|
const Meteor = { ...inMeteor };
|
|
120
117
|
// Convert string boolean values to actual booleans
|
|
@@ -232,6 +229,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
232
229
|
const externals = [
|
|
233
230
|
/^meteor.*/,
|
|
234
231
|
...(isReactEnabled ? [/^react$/, /^react-dom$/] : []),
|
|
232
|
+
...(isServer ? [/^bcrypt$/] : []),
|
|
235
233
|
];
|
|
236
234
|
const alias = {
|
|
237
235
|
'/': path.resolve(process.cwd()),
|