generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
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}`);
}
}));
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels