Hy Guys,
I have just a simple question. If I use require.context
to automatic import my files liked that:
const exportFile = (path, req) => {
const [, componentName] = path.match(/\.\/(.*)\/index.js?$/i);
const component = req(path);
module.exports[componentName] = component.default || component;
};
const requireAll = (ctx) =>
ctx.keys().forEach(path => exportFile(path, ctx));
requireAll(require.context('./', true, /\.\/(.*)\/index.js?$/i));
Webpack will make Tree Shaking as well?
Thanks!
tree shaking only works with ES
import
andexport
.require.context
!=import
is there any workaround to archive this? require.context is really useful but cannot use tree shaking is a big disadvantage.