@meteorjs/rspack 0.0.33 → 0.0.35
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/package.json +1 -1
- package/rspack.config.js +24 -19
- package/plugins/CleanBuildAssetsPlugin.js +0 -52
package/package.json
CHANGED
package/rspack.config.js
CHANGED
|
@@ -7,7 +7,6 @@ import { merge } from 'webpack-merge';
|
|
|
7
7
|
|
|
8
8
|
import { cleanOmittedPaths, mergeSplitOverlap } from "./lib/mergeRulesSplitOverlap.js";
|
|
9
9
|
import { getMeteorAppSwcConfig } from './lib/swc.js';
|
|
10
|
-
import CleanBuildAssetsPlugin from './plugins/CleanBuildAssetsPlugin.js';
|
|
11
10
|
import HtmlRspackPlugin from './plugins/HtmlRspackPlugin.js';
|
|
12
11
|
import { RequireExternalsPlugin } from './plugins/RequireExtenalsPlugin.js';
|
|
13
12
|
|
|
@@ -87,9 +86,9 @@ function createSwcConfig({
|
|
|
87
86
|
function keepOutsideBuild() {
|
|
88
87
|
return (p) => {
|
|
89
88
|
const normalized = '/' + path.normalize(p).replaceAll(path.sep, '/').replace(/^\/+/, '');
|
|
90
|
-
const isInBuildRoot = /\/
|
|
91
|
-
const isInBuildStar = /\/
|
|
92
|
-
return !(isInBuildRoot || isInBuildStar);
|
|
89
|
+
const isInBuildRoot = /\/build(\/|$)/.test(normalized);
|
|
90
|
+
const isInBuildStar = /\/build-[^/]+(\/|$)/.test(normalized);
|
|
91
|
+
return !(isInBuildRoot || isInBuildStar);
|
|
93
92
|
};
|
|
94
93
|
}
|
|
95
94
|
|
|
@@ -100,7 +99,7 @@ const defaultWatchOptions = {
|
|
|
100
99
|
|
|
101
100
|
/**
|
|
102
101
|
* @param {{ isClient: boolean; isServer: boolean; isDevelopment?: boolean; isProduction?: boolean; isTest?: boolean }} Meteor
|
|
103
|
-
* @param {{ mode?: string; clientEntry?: string; serverEntry?: string; clientOutputFolder?: string; serverOutputFolder?: string;
|
|
102
|
+
* @param {{ mode?: string; clientEntry?: string; serverEntry?: string; clientOutputFolder?: string; serverOutputFolder?: string; chunksContext?: string; assetsContext?: string; serverAssetsContext?: string }} argv
|
|
104
103
|
* @returns {import('@rspack/cli').Configuration[]}
|
|
105
104
|
*/
|
|
106
105
|
export default function (inMeteor = {}, argv = {}) {
|
|
@@ -133,7 +132,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
133
132
|
Meteor.isJsxEnabled || (!isTypescriptEnabled && isReactEnabled) || false;
|
|
134
133
|
const isTsxEnabled =
|
|
135
134
|
Meteor.isTsxEnabled || (isTypescriptEnabled && isReactEnabled) || false;
|
|
136
|
-
|
|
135
|
+
const isBundleVisualizerEnabled = Meteor.isBundleVisualizerEnabled || false;
|
|
137
136
|
|
|
138
137
|
// Determine entry points
|
|
139
138
|
const entryPath = Meteor.entryPath;
|
|
@@ -156,8 +155,8 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
156
155
|
|
|
157
156
|
// Determine context for bundles and assets
|
|
158
157
|
const buildContext = Meteor.buildContext || '_build';
|
|
159
|
-
const
|
|
160
|
-
const
|
|
158
|
+
const assetsContext = Meteor.assetsContext || 'build-assets';
|
|
159
|
+
const chunksContext = Meteor.chunksContext || 'build-chunks';
|
|
161
160
|
|
|
162
161
|
// Determine build output and pass to Meteor
|
|
163
162
|
const buildOutputDir = path.resolve(process.cwd(), buildContext, outputDir);
|
|
@@ -252,6 +251,17 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
252
251
|
enableGlobalPolyfill: isDevEnvironment,
|
|
253
252
|
});
|
|
254
253
|
|
|
254
|
+
const rsdoctorModule = isBundleVisualizerEnabled
|
|
255
|
+
? safeRequire('@rsdoctor/rspack-plugin')
|
|
256
|
+
: null;
|
|
257
|
+
const doctorPluginConfig = isBundleVisualizerEnabled && rsdoctorModule?.RsdoctorRspackPlugin
|
|
258
|
+
? [
|
|
259
|
+
new rsdoctorModule.RsdoctorRspackPlugin({
|
|
260
|
+
port: isClient ? 8081 : 8082,
|
|
261
|
+
}),
|
|
262
|
+
]
|
|
263
|
+
: [];
|
|
264
|
+
|
|
255
265
|
const clientNameConfig = `[${(isTest && 'test-') || ''}${
|
|
256
266
|
(isTestModule && 'module') || 'client'
|
|
257
267
|
}-rspack]`;
|
|
@@ -267,12 +277,12 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
267
277
|
isDevEnvironment ? outputFilename : `../${buildContext}/${outputPath}`,
|
|
268
278
|
libraryTarget: 'commonjs',
|
|
269
279
|
publicPath: '/',
|
|
270
|
-
chunkFilename: `${
|
|
280
|
+
chunkFilename: `${chunksContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
|
|
271
281
|
assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
|
|
272
|
-
cssFilename: `${
|
|
282
|
+
cssFilename: `${chunksContext}/[name]${
|
|
273
283
|
isProd ? '.[contenthash]' : ''
|
|
274
284
|
}.css`,
|
|
275
|
-
cssChunkFilename: `${
|
|
285
|
+
cssChunkFilename: `${chunksContext}/[id]${
|
|
276
286
|
isProd ? '.[contenthash]' : ''
|
|
277
287
|
}.css`,
|
|
278
288
|
...(isProd && { clean: { keep: keepOutsideBuild() } }),
|
|
@@ -298,13 +308,6 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
298
308
|
resolve: { extensions, alias },
|
|
299
309
|
externals,
|
|
300
310
|
plugins: [
|
|
301
|
-
...(isProd
|
|
302
|
-
? [
|
|
303
|
-
new CleanBuildAssetsPlugin({
|
|
304
|
-
verbose: Meteor.isDebug || Meteor.isVerbose,
|
|
305
|
-
}),
|
|
306
|
-
]
|
|
307
|
-
: []),
|
|
308
311
|
...[
|
|
309
312
|
...(isReactEnabled && reactRefreshModule && isDevEnvironment
|
|
310
313
|
? [new reactRefreshModule()]
|
|
@@ -324,6 +327,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
324
327
|
entryOnly: true,
|
|
325
328
|
}),
|
|
326
329
|
Meteor.HtmlRspackPlugin(),
|
|
330
|
+
...doctorPluginConfig,
|
|
327
331
|
],
|
|
328
332
|
watchOptions,
|
|
329
333
|
devtool: isDevEnvironment || isNative || isTest ? 'source-map' : 'hidden-source-map',
|
|
@@ -362,7 +366,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
362
366
|
path: serverOutputDir,
|
|
363
367
|
filename: () => `../${buildContext}/${outputPath}`,
|
|
364
368
|
libraryTarget: 'commonjs',
|
|
365
|
-
chunkFilename: `${
|
|
369
|
+
chunkFilename: `${chunksContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
|
|
366
370
|
assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
|
|
367
371
|
...(isProd && { clean: { keep: keepOutsideBuild() } }),
|
|
368
372
|
},
|
|
@@ -405,6 +409,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
405
409
|
entryOnly: true,
|
|
406
410
|
}),
|
|
407
411
|
isTestModule && requireExternalsPlugin,
|
|
412
|
+
...doctorPluginConfig,
|
|
408
413
|
],
|
|
409
414
|
watchOptions,
|
|
410
415
|
devtool: isDevEnvironment || isNative || isTest ? 'source-map' : 'hidden-source-map',
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Rspack plugin to clean and recreate build directories
|
|
6
|
-
* before each compilation.
|
|
7
|
-
*
|
|
8
|
-
* Options:
|
|
9
|
-
* - targets {string[]} : Directories to clean.
|
|
10
|
-
* Defaults:
|
|
11
|
-
* - public/_build-assets
|
|
12
|
-
* - public/_build-bundles
|
|
13
|
-
* - private/_build-assets
|
|
14
|
-
* - verbose {boolean} : If true, logs cleaning operations. Default: false
|
|
15
|
-
*/
|
|
16
|
-
export default class CleanBuildAssetsPlugin {
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
const defaults = [
|
|
19
|
-
'public/_build-assets',
|
|
20
|
-
'private/_build-assets',
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
this.targets = Array.isArray(options.targets)
|
|
24
|
-
? options.targets
|
|
25
|
-
: defaults;
|
|
26
|
-
|
|
27
|
-
this.verbose = options.verbose || false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
apply(compiler) {
|
|
31
|
-
compiler.hooks.beforeRun.tapPromise(
|
|
32
|
-
'CleanBuildAssetsPlugin',
|
|
33
|
-
async () => {
|
|
34
|
-
for (const target of this.targets) {
|
|
35
|
-
const dir = path.resolve(compiler.context, target);
|
|
36
|
-
try {
|
|
37
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
38
|
-
await fs.mkdir(dir, { recursive: true });
|
|
39
|
-
if (this.verbose) {
|
|
40
|
-
console.log(`[CleanBuildAssetsPlugin] Cleaned: ${dir}`);
|
|
41
|
-
}
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.warn(
|
|
44
|
-
`[CleanBuildAssetsPlugin] Failed to clean ${dir}:`,
|
|
45
|
-
err.message
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
}
|