improve webpack clean configuration with build folder filtering

This commit is contained in:
Nacho Codoñer
2025-08-20 16:28:11 +02:00
parent 324d8b8aa8
commit cdb62e0de1
4 changed files with 16 additions and 6 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.29",
"version": "0.0.30",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@meteorjs/rspack",
"version": "0.0.29",
"version": "0.0.30",
"license": "ISC",
"dependencies": {
"ignore-loader": "^0.1.2",

View File

@@ -1,6 +1,6 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.29",
"version": "0.0.30",
"description": "Configuration logic for using Rspack in Meteor projects",
"main": "index.js",
"type": "module",

View File

@@ -98,6 +98,16 @@ function createCoffeescriptConfig({ swcConfig }) {
};
}
// Keep files outside of build folders
function keepOutsideBuild() {
return (p) => {
const normalized = '/' + path.normalize(p).replaceAll(path.sep, '/').replace(/^\/+/, '');
const isInBuildRoot = /\/_build(\/|$)/.test(normalized);
const isInBuildStar = /\/_build-[^/]+(\/|$)/.test(normalized);
return !(isInBuildRoot || isInBuildStar); // true => KEEP, false => DELETE
};
}
// Watch options shared across both builds
const defaultWatchOptions = {
ignored: ['**/.meteor/local/**', '**/dist/**'],
@@ -282,7 +292,7 @@ export default function (inMeteor = {}, argv = {}) {
cssChunkFilename: `${assetsContext}/[id]${
isProd ? '.[contenthash]' : ''
}.css`,
clean: isProd,
...(isProd && { clean: { keep: keepOutsideBuild() } }),
},
optimization: {
usedExports: true,
@@ -371,7 +381,7 @@ export default function (inMeteor = {}, argv = {}) {
libraryTarget: 'commonjs',
chunkFilename: `${bundlesContext}/[id]${isProd ? '.[chunkhash]' : ''}.js`,
assetModuleFilename: `${assetsContext}/[hash][ext][query]`,
clean: isProd,
...(isProd && { clean: { keep: keepOutsideBuild() } }),
},
optimization: { usedExports: true },
module: {

View File

@@ -5,7 +5,7 @@
export const DEFAULT_RSPACK_VERSION = '1.4.8';
export const DEFAULT_METEOR_RSPACK_VERSION = '0.0.29';
export const DEFAULT_METEOR_RSPACK_VERSION = '0.0.30';
export const DEFAULT_METEOR_RSPACK_REACT_HMR_VERSION = '1.4.3';