Skip to content

Commit

Permalink
Merge pull request #17 from torusresearch/fix/webpack-loader
Browse files Browse the repository at this point in the history
fix loaders
  • Loading branch information
chaitanyapotti authored Feb 4, 2022
2 parents 0d1182d + c6e5e33 commit 01488f5
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions packages/torus-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,48 @@ function generateLibraryName(pkgName) {
return pkgName.charAt(0).toUpperCase() + pkgName.slice(1);
}

// objValue is the first object (our default config)
function customizer(objValue, srcValue, key) {
// merge plugins if they are not there
if (Array.isArray(objValue) && (key === "plugins" || key === "rules")) {
return [...objValue, ...(srcValue || [])];
}
}

module.exports = (pkgName) => {
const baseConfig = merge(getDefaultBaseConfig(pkgName), userBaseConfig);
const umdConfig = merge(getDefaultUmdConfig(pkgName), baseConfig, rest.umdConfig || {});
const cjsConfig = merge(getDefaultCjsConfig(pkgName), baseConfig, rest.cjsConfig || {});
const cjsBundledConfig = merge(getDefaultCjsBundledConfig(pkgName), baseConfig, rest.cjsBundledConfig || {});
// create a copy of baseConfig every time so that loaders use new instances
const umdConfig = merge(
getDefaultUmdConfig(pkgName),
merge(getDefaultBaseConfig(pkgName), userBaseConfig, customizer),
rest.umdConfig || {},
customizer
);
const cjsConfig = merge(
getDefaultCjsConfig(pkgName),
merge(getDefaultBaseConfig(pkgName), userBaseConfig, customizer),
rest.cjsConfig || {},
customizer
);
const cjsBundledConfig = merge(
getDefaultCjsBundledConfig(pkgName),
merge(getDefaultBaseConfig(pkgName), userBaseConfig, customizer),
rest.cjsBundledConfig || {},
customizer
);

const finalConfigs = [];

if (torusConfig.cjs) finalConfigs.push(cjsConfig);
if (torusConfig.umd) finalConfigs.push(umdConfig);
if (torusConfig.cjsBundled) finalConfigs.push(cjsBundledConfig);

// console.log("%O", ...finalConfigs.map(x => x.plugins));

return [
...finalConfigs,
...Object.values(rest || {}).map((x) => {
return merge(baseConfig, x);
const baseConfig = merge(getDefaultBaseConfig(pkgName), userBaseConfig, customizer);
return merge(baseConfig, x, customizer);
}),
];
};
Expand Down

0 comments on commit 01488f5

Please sign in to comment.