@meteorjs/rspack 0.0.60 → 0.0.61

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 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
- cache: false, // disable cache
74
- experiments: {
75
- cache: false, // disable persistent cache (experimental flag)
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); // e.g. 'fs'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteorjs/rspack",
3
- "version": "0.0.60",
3
+ "version": "0.0.61",
4
4
  "description": "Configuration logic for using Rspack in Meteor projects",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
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
 
@@ -273,6 +274,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
273
274
  !!enabled,
274
275
  enabled === 'memory' ? undefined : cacheStrategy
275
276
  );
277
+ Meteor.splitVendorChunk = () => splitVendorChunk();
276
278
 
277
279
  // Add HtmlRspackPlugin function to Meteor
278
280
  Meteor.HtmlRspackPlugin = (options = {}) => {
@@ -611,10 +613,15 @@ module.exports = async function (inMeteor = {}, argv = {}) {
611
613
  throw error;
612
614
  }
613
615
 
614
- const userConfig =
616
+ const rawUserConfig =
615
617
  typeof projectConfig === 'function'
616
618
  ? projectConfig(Meteor, argv)
617
619
  : projectConfig;
620
+ const resolvedUserConfig = await Promise.resolve(rawUserConfig);
621
+ const userConfig =
622
+ resolvedUserConfig && '0' in resolvedUserConfig
623
+ ? resolvedUserConfig[0]
624
+ : resolvedUserConfig;
618
625
 
619
626
  const omitPaths = [
620
627
  "name",