chore: tree shaking
This commit is contained in:
parent
611b41e96a
commit
8b720619a5
|
@ -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
4
app/util/eval.js
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user