ESM export default {...object} All In One
object destructuring & module export default
erros
export {...obj}
❌
const Metrics = {
autoReport,
manualReport,
};
export {
...Metrics,
};
export default Metrics;
demos
export default {...obj}
✅
const autoReport = () => console.log(`autoReport`);
const manualReport = () => console.log(`manualReport`);
const Metrics = {
autoReport,
manualReport,
};
export {
autoReport,
manualReport,
};
// export default Metrics;
// OR
export default {
...Metrics
};
// import { autoReport, manualReport, } from "./index.js";
import Metrics, { autoReport, manualReport, } from "./index.js";
if(autoReport && manualReport) {
console.log(`app ✅`);
autoReport();
manualReport();
console.log(`Metrics ✅`);
Metrics.autoReport();
Metrics.manualReport();
} else {
console.log(`app ❌`);
}
https://gist.github.com/xgqfrms/7abacf4807cd00f046bc53fb6d9a4118