chore: tree shaking

This commit is contained in:
cha0s 2024-10-16 18:47:48 -05:00
parent 611b41e96a
commit 8b720619a5
2 changed files with 26 additions and 7 deletions

View File

@ -4,15 +4,30 @@ const Gathered = gather(
import.meta.glob(['./*.js', '!./*.test.js'], {eager: true, import: 'default'}),
);
let wrapComponent;
if (import.meta.env.PROD) {
wrapComponent = (componentName, Component) => (
class extends Component {
static componentName = componentName;
}
);
}
else {
const {default: ieval} = await import('@/util/eval.js');
wrapComponent = (componentName, Component) => (
ieval(`
((Component) => (
class ${componentName} extends Component {
static componentName = '${componentName}';
}
))
`)(Component)
);
}
const Components = {};
for (const componentName in Gathered) {
Components[componentName] = eval(`
((Gathered) => (
class ${componentName} extends Gathered['${componentName}'] {
static componentName = '${componentName}';
}
))
`)(Gathered);
Components[componentName] = wrapComponent(componentName, Gathered[componentName]);
}
export default Components;

4
app/util/eval.js Normal file
View File

@ -0,0 +1,4 @@
// this is only here to avoid build warnings that should have been tree-shaken away
export default function importedEval(code) {
return eval(code);
}