In order to polyfill node:path for example we need to use NormalModuleReplacementPlugin (webpack/webpack#13290 (comment))
I think that would be nice for app-builder to map config.fallback, and include polyfills from here
For example we have
{
fallback: {
path: require.resolve('path-browserify')
}
}
My proposal to make mapping to final webpack config like:
if (config.fallback) {
const polyfills: string[] = [];
for (const fallback of config.fallback) {
const polyfill = config.fallback[fallback];
// We also could check that it is builtin node module polyfill
if (typeof polyfill === 'string') {
polyfills.push(polyfill);
}
}
if (polyfills.length) {
config.plugins.push(new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, "");
if (polyfills.includes(mod)) {
resource.request = config.polyfills[mod];
} else {
throw new Error(`Not found ${mod}`);
}
}));
}
}
In order to polyfill
node:pathfor example we need to useNormalModuleReplacementPlugin(webpack/webpack#13290 (comment))I think that would be nice for app-builder to map
config.fallback, and include polyfills from hereFor example we have
My proposal to make mapping to final webpack config like: