@meteorjs/rspack 0.0.67 → 0.1.0
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 +98 -64
package/package.json
CHANGED
package/rspack.config.js
CHANGED
|
@@ -604,83 +604,92 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
604
604
|
cacheStrategy),
|
|
605
605
|
};
|
|
606
606
|
|
|
607
|
-
//
|
|
608
|
-
|
|
609
|
-
const isMeteorPackageConfig = projectDir.includes('/packages/rspack');
|
|
610
|
-
if (fs.existsSync(projectConfigPath) && !isMeteorPackageConfig) {
|
|
611
|
-
// Check if there's a .mjs or .cjs version of the config file
|
|
612
|
-
const mjsConfigPath = projectConfigPath.replace(/\.js$/, '.mjs');
|
|
613
|
-
const cjsConfigPath = projectConfigPath.replace(/\.js$/, '.cjs');
|
|
614
|
-
|
|
615
|
-
let configPath = projectConfigPath;
|
|
616
|
-
if (fs.existsSync(mjsConfigPath)) {
|
|
617
|
-
configPath = mjsConfigPath;
|
|
618
|
-
} else if (fs.existsSync(cjsConfigPath)) {
|
|
619
|
-
configPath = cjsConfigPath;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// Use require for CommonJS modules and dynamic import for ES modules
|
|
623
|
-
let projectConfig;
|
|
607
|
+
// Helper function to load and process config files
|
|
608
|
+
async function loadAndProcessConfig(configPath, configType, Meteor, argv, isAngularEnabled) {
|
|
624
609
|
try {
|
|
610
|
+
// Load the config file
|
|
611
|
+
let config;
|
|
625
612
|
if (path.extname(configPath) === '.mjs') {
|
|
626
613
|
// For ESM modules, we need to use dynamic import
|
|
627
614
|
const fileUrl = `file://${configPath}`;
|
|
628
615
|
const module = await import(fileUrl);
|
|
629
|
-
|
|
616
|
+
config = module.default || module;
|
|
630
617
|
} else {
|
|
631
618
|
// For CommonJS modules, we can use require
|
|
632
|
-
|
|
619
|
+
config = require(configPath)?.default || require(configPath);
|
|
633
620
|
}
|
|
621
|
+
|
|
622
|
+
// Process the config
|
|
623
|
+
const rawConfig = typeof config === 'function' ? config(Meteor, argv) : config;
|
|
624
|
+
const resolvedConfig = await Promise.resolve(rawConfig);
|
|
625
|
+
const userConfig = resolvedConfig && '0' in resolvedConfig ? resolvedConfig[0] : resolvedConfig;
|
|
626
|
+
|
|
627
|
+
// Define omitted paths and warning function
|
|
628
|
+
const omitPaths = [
|
|
629
|
+
"name",
|
|
630
|
+
"target",
|
|
631
|
+
"entry",
|
|
632
|
+
"output.path",
|
|
633
|
+
"output.filename",
|
|
634
|
+
"output.publicPath",
|
|
635
|
+
...(Meteor.isServer ? ["optimization.splitChunks", "optimization.runtimeChunk"] : []),
|
|
636
|
+
].filter(Boolean);
|
|
637
|
+
|
|
638
|
+
const warningFn = path => {
|
|
639
|
+
if (isAngularEnabled) return;
|
|
640
|
+
console.warn(
|
|
641
|
+
`[${configType}] Ignored custom "${path}" — reserved for Meteor-Rspack integration.`,
|
|
642
|
+
);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// Clean omitted paths and merge Meteor Rspack fragments
|
|
646
|
+
let nextConfig = cleanOmittedPaths(userConfig, {
|
|
647
|
+
omitPaths,
|
|
648
|
+
warningFn,
|
|
649
|
+
});
|
|
650
|
+
nextConfig = mergeMeteorRspackFragments(nextConfig);
|
|
651
|
+
|
|
652
|
+
return nextConfig;
|
|
634
653
|
} catch (error) {
|
|
635
|
-
console.error(`Error loading
|
|
636
|
-
|
|
654
|
+
console.error(`Error loading ${configType} from ${configPath}:`, error);
|
|
655
|
+
if (configType === 'rspack.config.js') {
|
|
656
|
+
throw error; // Only rethrow for project config
|
|
657
|
+
}
|
|
658
|
+
return null;
|
|
637
659
|
}
|
|
660
|
+
}
|
|
638
661
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
: resolvedUserConfig;
|
|
648
|
-
|
|
649
|
-
const omitPaths = [
|
|
650
|
-
"name",
|
|
651
|
-
"target",
|
|
652
|
-
"entry",
|
|
653
|
-
"output.path",
|
|
654
|
-
"output.filename",
|
|
655
|
-
"output.publicPath",
|
|
656
|
-
...(Meteor.isServer
|
|
657
|
-
? ["optimization.splitChunks", "optimization.runtimeChunk"]
|
|
658
|
-
: []),
|
|
659
|
-
].filter(Boolean);
|
|
660
|
-
const warningFn = path => {
|
|
661
|
-
if (isAngularEnabled) return;
|
|
662
|
-
console.warn(
|
|
663
|
-
`[rspack.config.js] Ignored custom "${path}" — reserved for Meteor-Rspack integration.`,
|
|
664
|
-
);
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
let nextUserConfig = cleanOmittedPaths(userConfig, {
|
|
668
|
-
omitPaths,
|
|
669
|
-
warningFn,
|
|
670
|
-
});
|
|
671
|
-
nextUserConfig = mergeMeteorRspackFragments(nextUserConfig);
|
|
662
|
+
// Load and apply project-level overrides for the selected build
|
|
663
|
+
// Check if we're in a Meteor package directory by looking at the path
|
|
664
|
+
const isMeteorPackageConfig = projectDir.includes('/packages/rspack');
|
|
665
|
+
console.log("--> (rspack.config.js-Line: 665)\n isMeteorPackageConfig: ", isMeteorPackageConfig);
|
|
666
|
+
if (fs.existsSync(projectConfigPath) && !isMeteorPackageConfig) {
|
|
667
|
+
// Check if there's a .mjs or .cjs version of the config file
|
|
668
|
+
const mjsConfigPath = projectConfigPath.replace(/\.js$/, '.mjs');
|
|
669
|
+
const cjsConfigPath = projectConfigPath.replace(/\.js$/, '.cjs');
|
|
672
670
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
671
|
+
let projectConfigPathToUse = projectConfigPath;
|
|
672
|
+
if (fs.existsSync(mjsConfigPath)) {
|
|
673
|
+
projectConfigPathToUse = mjsConfigPath;
|
|
674
|
+
} else if (fs.existsSync(cjsConfigPath)) {
|
|
675
|
+
projectConfigPathToUse = cjsConfigPath;
|
|
678
676
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
677
|
+
|
|
678
|
+
const nextUserConfig = await loadAndProcessConfig(
|
|
679
|
+
projectConfigPathToUse,
|
|
680
|
+
'rspack.config.js',
|
|
681
|
+
Meteor,
|
|
682
|
+
argv,
|
|
683
|
+
isAngularEnabled
|
|
684
|
+
);
|
|
685
|
+
|
|
686
|
+
if (nextUserConfig) {
|
|
687
|
+
if (Meteor.isClient) {
|
|
688
|
+
clientConfig = mergeSplitOverlap(clientConfig, nextUserConfig);
|
|
689
|
+
}
|
|
690
|
+
if (Meteor.isServer) {
|
|
691
|
+
serverConfig = mergeSplitOverlap(serverConfig, nextUserConfig);
|
|
692
|
+
}
|
|
684
693
|
}
|
|
685
694
|
}
|
|
686
695
|
|
|
@@ -721,6 +730,31 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
721
730
|
);
|
|
722
731
|
config = mergeSplitOverlap(config, testClientExpandConfig);
|
|
723
732
|
|
|
733
|
+
// Check for override config file (extra file to override everything)
|
|
734
|
+
if (projectConfigPath) {
|
|
735
|
+
const configDir = path.dirname(projectConfigPath);
|
|
736
|
+
const configFileName = path.basename(projectConfigPath);
|
|
737
|
+
const configExt = path.extname(configFileName);
|
|
738
|
+
const configNameWithoutExt = configFileName.replace(configExt, '');
|
|
739
|
+
const configNameFull = `${configNameWithoutExt}.override${configExt}`;
|
|
740
|
+
const overrideConfigPath = path.join(configDir, configNameFull);
|
|
741
|
+
|
|
742
|
+
if (fs.existsSync(overrideConfigPath)) {
|
|
743
|
+
const nextOverrideConfig = await loadAndProcessConfig(
|
|
744
|
+
overrideConfigPath,
|
|
745
|
+
configNameFull,
|
|
746
|
+
Meteor,
|
|
747
|
+
argv,
|
|
748
|
+
isAngularEnabled
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
if (nextOverrideConfig) {
|
|
752
|
+
// Apply override config as the last step
|
|
753
|
+
config = mergeSplitOverlap(config, nextOverrideConfig);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
724
758
|
if (Meteor.isDebug || Meteor.isVerbose) {
|
|
725
759
|
console.log('Config:', inspect(config, { depth: null, colors: true }));
|
|
726
760
|
}
|