@meteorjs/rspack 0.0.60 → 0.0.62
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 +26 -1
- package/lib/meteorRspackHelpers.js +33 -7
- package/package.json +1 -1
- package/rspack.config.js +26 -2
package/index.d.ts
CHANGED
|
@@ -5,7 +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
|
+
import { HtmlRspackPluginOptions, RuleSetConditions } from '@rspack/core';
|
|
9
9
|
|
|
10
10
|
export interface MeteorRspackConfig extends _RspackConfig {
|
|
11
11
|
meteor?: {
|
|
@@ -31,6 +31,31 @@ type MeteorEnv = Record<string, any> & {
|
|
|
31
31
|
* @returns An instance of HtmlRspackPlugin
|
|
32
32
|
*/
|
|
33
33
|
HtmlRspackPlugin: (options?: HtmlRspackPluginOptions) => HtmlRspackPlugin;
|
|
34
|
+
/**
|
|
35
|
+
* Wrap externals for Meteor runtime.
|
|
36
|
+
* @param deps - Package names or module IDs
|
|
37
|
+
* @returns A config object with externals configuration
|
|
38
|
+
*/
|
|
39
|
+
compileWithMeteor: (deps: RuleSetConditions) => Record<string, object>;
|
|
40
|
+
/**
|
|
41
|
+
* Add SWC transpilation rules limited to specific deps (monorepo-friendly).
|
|
42
|
+
* @param deps - Package names to include in SWC loader
|
|
43
|
+
* @param options - Optional configuration options
|
|
44
|
+
* @returns A config object with module rules configuration
|
|
45
|
+
*/
|
|
46
|
+
compileWithRspack: (deps: RuleSetConditions) => Record<string, object>;
|
|
47
|
+
/**
|
|
48
|
+
* Enable or disable Rspack cache config.
|
|
49
|
+
* @param enabled - Whether to enable caching
|
|
50
|
+
* @param cacheConfig - Optional cache configuration
|
|
51
|
+
* @returns A config object with cache configuration
|
|
52
|
+
*/
|
|
53
|
+
setCache: (enabled: boolean | 'memory') => Record<string, object>;
|
|
54
|
+
/**
|
|
55
|
+
* Enable Rspack split vendor chunk.
|
|
56
|
+
* @returns A config object with optimization configuration
|
|
57
|
+
*/
|
|
58
|
+
splitVendorChunk: () => Record<string, object>;
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
export type ConfigFactory = (
|
|
@@ -64,17 +64,17 @@ function compileWithRspack(deps, { options = {} } = {}) {
|
|
|
64
64
|
*/
|
|
65
65
|
function setCache(
|
|
66
66
|
enabled,
|
|
67
|
-
cacheConfig = { cache: true, experiments: { cache: true } }
|
|
67
|
+
cacheConfig = { cache: true, experiments: { cache: true } }
|
|
68
68
|
) {
|
|
69
69
|
return prepareMeteorRspackConfig(
|
|
70
70
|
enabled
|
|
71
71
|
? cacheConfig
|
|
72
72
|
: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
cache: false, // disable cache
|
|
74
|
+
experiments: {
|
|
75
|
+
cache: false, // disable persistent cache (experimental flag)
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -89,7 +89,7 @@ function makeWebNodeBuiltinsAlias(extras = []) {
|
|
|
89
89
|
|
|
90
90
|
const names = new Set();
|
|
91
91
|
for (const m of core) {
|
|
92
|
-
names.add(m);
|
|
92
|
+
names.add(m); // e.g. 'fs'
|
|
93
93
|
names.add(`node:${m}`); // e.g. 'node:fs'
|
|
94
94
|
}
|
|
95
95
|
for (const x of extras) names.add(x);
|
|
@@ -98,9 +98,35 @@ function makeWebNodeBuiltinsAlias(extras = []) {
|
|
|
98
98
|
return Object.fromEntries([...names].map((m) => [m, false]));
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Enable Rspack split vendor chunk config
|
|
103
|
+
* Usage: splitVendorChunk()
|
|
104
|
+
*
|
|
105
|
+
* @returns {Record<string, object>} `{ meteorRspackConfigX: { optimization: { ... } } }`
|
|
106
|
+
*/
|
|
107
|
+
function splitVendorChunk() {
|
|
108
|
+
return prepareMeteorRspackConfig({
|
|
109
|
+
optimization: {
|
|
110
|
+
splitChunks: {
|
|
111
|
+
chunks: "all", // split both sync and async imports
|
|
112
|
+
cacheGroups: {
|
|
113
|
+
vendor: {
|
|
114
|
+
test: /[\\/]node_modules[\\/]/,
|
|
115
|
+
name: "vendor",
|
|
116
|
+
enforce: true,
|
|
117
|
+
priority: 10,
|
|
118
|
+
chunks: "all",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
101
126
|
module.exports = {
|
|
102
127
|
compileWithMeteor,
|
|
103
128
|
compileWithRspack,
|
|
104
129
|
setCache,
|
|
130
|
+
splitVendorChunk,
|
|
105
131
|
makeWebNodeBuiltinsAlias,
|
|
106
132
|
};
|
package/package.json
CHANGED
package/rspack.config.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
compileWithMeteor,
|
|
16
16
|
compileWithRspack,
|
|
17
17
|
setCache,
|
|
18
|
+
splitVendorChunk,
|
|
18
19
|
makeWebNodeBuiltinsAlias,
|
|
19
20
|
} = require('./lib/meteorRspackHelpers.js');
|
|
20
21
|
|
|
@@ -94,6 +95,7 @@ function createSwcConfig({
|
|
|
94
95
|
externalHelpers,
|
|
95
96
|
isDevEnvironment,
|
|
96
97
|
isClient,
|
|
98
|
+
isAngularEnabled,
|
|
97
99
|
}) {
|
|
98
100
|
const defaultConfig = {
|
|
99
101
|
jsc: {
|
|
@@ -103,6 +105,7 @@ function createSwcConfig({
|
|
|
103
105
|
syntax: isTypescriptEnabled ? 'typescript' : 'ecmascript',
|
|
104
106
|
...(isTsxEnabled && { tsx: true }),
|
|
105
107
|
...(isJsxEnabled && { jsx: true }),
|
|
108
|
+
...(isAngularEnabled && { decorators: true }),
|
|
106
109
|
},
|
|
107
110
|
target: 'es2015',
|
|
108
111
|
...(isReactEnabled && {
|
|
@@ -227,6 +230,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
227
230
|
const isTsxEnabled =
|
|
228
231
|
Meteor.isTsxEnabled || (isTypescriptEnabled && isReactEnabled) || false;
|
|
229
232
|
const isBundleVisualizerEnabled = Meteor.isBundleVisualizerEnabled || false;
|
|
233
|
+
const isAngularEnabled = Meteor.isAngularEnabled || false;
|
|
230
234
|
|
|
231
235
|
// Determine entry points
|
|
232
236
|
const entryPath = Meteor.entryPath;
|
|
@@ -273,6 +277,8 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
273
277
|
!!enabled,
|
|
274
278
|
enabled === 'memory' ? undefined : cacheStrategy
|
|
275
279
|
);
|
|
280
|
+
Meteor.splitVendorChunk = () => splitVendorChunk();
|
|
281
|
+
Meteor.createAngularConfig = () => createAngularConfig();
|
|
276
282
|
|
|
277
283
|
// Add HtmlRspackPlugin function to Meteor
|
|
278
284
|
Meteor.HtmlRspackPlugin = (options = {}) => {
|
|
@@ -333,6 +339,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
333
339
|
externalHelpers: enableSwcExternalHelpers,
|
|
334
340
|
isDevEnvironment,
|
|
335
341
|
isClient,
|
|
342
|
+
isAngularEnabled,
|
|
336
343
|
});
|
|
337
344
|
// Expose swc config to use in custom configs
|
|
338
345
|
Meteor.swcConfigOptions = swcConfigRule.options;
|
|
@@ -611,10 +618,15 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
611
618
|
throw error;
|
|
612
619
|
}
|
|
613
620
|
|
|
614
|
-
const
|
|
621
|
+
const rawUserConfig =
|
|
615
622
|
typeof projectConfig === 'function'
|
|
616
623
|
? projectConfig(Meteor, argv)
|
|
617
624
|
: projectConfig;
|
|
625
|
+
const resolvedUserConfig = await Promise.resolve(rawUserConfig);
|
|
626
|
+
const userConfig =
|
|
627
|
+
resolvedUserConfig && '0' in resolvedUserConfig
|
|
628
|
+
? resolvedUserConfig[0]
|
|
629
|
+
: resolvedUserConfig;
|
|
618
630
|
|
|
619
631
|
const omitPaths = [
|
|
620
632
|
"name",
|
|
@@ -628,6 +640,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
628
640
|
: []),
|
|
629
641
|
].filter(Boolean);
|
|
630
642
|
const warningFn = path => {
|
|
643
|
+
if (isAngularEnabled) return;
|
|
631
644
|
console.warn(
|
|
632
645
|
`[rspack.config.js] Ignored custom "${path}" — reserved for Meteor-Rspack integration.`,
|
|
633
646
|
);
|
|
@@ -653,7 +666,18 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
653
666
|
}
|
|
654
667
|
}
|
|
655
668
|
|
|
656
|
-
|
|
669
|
+
// Establish Angular overrides to ensure proper integration
|
|
670
|
+
const angularExpandConfig = isAngularEnabled ? {
|
|
671
|
+
mode: isProd ? 'production' : 'development',
|
|
672
|
+
devServer: { port: Meteor.devServerPort },
|
|
673
|
+
stats: { preset: 'normal' },
|
|
674
|
+
infrastructureLogging: { level: 'info' },
|
|
675
|
+
} : {};
|
|
676
|
+
|
|
677
|
+
const config = mergeSplitOverlap(
|
|
678
|
+
isClient ? clientConfig : serverConfig,
|
|
679
|
+
angularExpandConfig
|
|
680
|
+
);
|
|
657
681
|
|
|
658
682
|
if (Meteor.isDebug || Meteor.isVerbose) {
|
|
659
683
|
console.log('Config:', inspect(config, { depth: null, colors: true }));
|