@meteorjs/rspack 0.0.32 → 0.0.34
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 +15 -22
- 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 = {}) {
|
|
@@ -125,6 +124,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
125
124
|
const isTestEager = !!Meteor.isTestEager;
|
|
126
125
|
const isTestFullApp = !!Meteor.isTestFullApp;
|
|
127
126
|
const swcExternalHelpers = !!Meteor.swcExternalHelpers;
|
|
127
|
+
const isNative = !!Meteor.isNative;
|
|
128
128
|
const mode = isProd ? 'production' : 'development';
|
|
129
129
|
|
|
130
130
|
const isTypescriptEnabled = Meteor.isTypescriptEnabled || false;
|
|
@@ -155,8 +155,8 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
155
155
|
|
|
156
156
|
// Determine context for bundles and assets
|
|
157
157
|
const buildContext = Meteor.buildContext || '_build';
|
|
158
|
-
const
|
|
159
|
-
const
|
|
158
|
+
const assetsContext = Meteor.assetsContext || 'build-assets';
|
|
159
|
+
const chunksContext = Meteor.chunksContext || 'build-chunks';
|
|
160
160
|
|
|
161
161
|
// Determine build output and pass to Meteor
|
|
162
162
|
const buildOutputDir = path.resolve(process.cwd(), buildContext, outputDir);
|
|
@@ -203,7 +203,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
203
203
|
console.log('[i] Meteor flags:', Meteor);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
const isDevEnvironment = isRun && isDev && !isTest;
|
|
206
|
+
const isDevEnvironment = isRun && isDev && !isTest && !isNative;
|
|
207
207
|
const swcConfigRule = createSwcConfig({
|
|
208
208
|
isTypescriptEnabled,
|
|
209
209
|
isJsxEnabled,
|
|
@@ -266,12 +266,12 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
266
266
|
isDevEnvironment ? outputFilename : `../${buildContext}/${outputPath}`,
|
|
267
267
|
libraryTarget: 'commonjs',
|
|
268
268
|
publicPath: '/',
|
|
269
|
-
chunkFilename: `${
|
|
269
|
+
chunkFilename: `${chunksContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
|
|
270
270
|
assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
|
|
271
|
-
cssFilename: `${
|
|
271
|
+
cssFilename: `${chunksContext}/[name]${
|
|
272
272
|
isProd ? '.[contenthash]' : ''
|
|
273
273
|
}.css`,
|
|
274
|
-
cssChunkFilename: `${
|
|
274
|
+
cssChunkFilename: `${chunksContext}/[id]${
|
|
275
275
|
isProd ? '.[contenthash]' : ''
|
|
276
276
|
}.css`,
|
|
277
277
|
...(isProd && { clean: { keep: keepOutsideBuild() } }),
|
|
@@ -297,13 +297,6 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
297
297
|
resolve: { extensions, alias },
|
|
298
298
|
externals,
|
|
299
299
|
plugins: [
|
|
300
|
-
...(isProd
|
|
301
|
-
? [
|
|
302
|
-
new CleanBuildAssetsPlugin({
|
|
303
|
-
verbose: Meteor.isDebug || Meteor.isVerbose,
|
|
304
|
-
}),
|
|
305
|
-
]
|
|
306
|
-
: []),
|
|
307
300
|
...[
|
|
308
301
|
...(isReactEnabled && reactRefreshModule && isDevEnvironment
|
|
309
302
|
? [new reactRefreshModule()]
|
|
@@ -325,7 +318,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
325
318
|
Meteor.HtmlRspackPlugin(),
|
|
326
319
|
],
|
|
327
320
|
watchOptions,
|
|
328
|
-
devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',
|
|
321
|
+
devtool: isDevEnvironment || isNative || isTest ? 'source-map' : 'hidden-source-map',
|
|
329
322
|
...(isDevEnvironment && {
|
|
330
323
|
devServer: {
|
|
331
324
|
static: { directory: clientOutputDir, publicPath: '/__rspack__/' },
|
|
@@ -361,7 +354,7 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
361
354
|
path: serverOutputDir,
|
|
362
355
|
filename: () => `../${buildContext}/${outputPath}`,
|
|
363
356
|
libraryTarget: 'commonjs',
|
|
364
|
-
chunkFilename: `${
|
|
357
|
+
chunkFilename: `${chunksContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
|
|
365
358
|
assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
|
|
366
359
|
...(isProd && { clean: { keep: keepOutsideBuild() } }),
|
|
367
360
|
},
|
|
@@ -406,8 +399,8 @@ export default function (inMeteor = {}, argv = {}) {
|
|
|
406
399
|
isTestModule && requireExternalsPlugin,
|
|
407
400
|
],
|
|
408
401
|
watchOptions,
|
|
409
|
-
devtool: isDevEnvironment || isTest ? 'source-map' : 'hidden-source-map',
|
|
410
|
-
...((isDevEnvironment || (isTest && !isTestEager)) &&
|
|
402
|
+
devtool: isDevEnvironment || isNative || isTest ? 'source-map' : 'hidden-source-map',
|
|
403
|
+
...((isDevEnvironment || (isTest && !isTestEager) || isNative) &&
|
|
411
404
|
createCacheStrategy(mode)),
|
|
412
405
|
};
|
|
413
406
|
|
|
@@ -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
|
-
}
|