fuse-box / fuse-box

A blazing fast js bundler/loader with a comprehensive API :fire:
http://fuse-box.org
MIT License
4k stars 237 forks source link

ESM output support #2018

Open charsleysa opened 3 years ago

charsleysa commented 3 years ago

Are there any plans for supporting ESModule output?

I see a lot of other tools and packages are switching the ESModule output, some exclusively only output ESModule and ditching UMD/AMD/CommonJS.

Would be great if fuse-box supported this as we are looking to switch over to ESModule output.

jpike88 commented 3 years ago

If anyone is having issues pulling in ESM modules into fusebox for the time being, use a library like simport which will make that lib compatible with fusebox.

Here's an example using 'p-queue', a pure ESM lib (and synchronised promise so it could be run on top level)


import PQueue from 'p-queue';
import sp from 'synchronized-promise';
import { createSimport } from 'simport';

const simport = createSimport(__filename);

const importPqueue = () => {
    return new Promise(async (resolve) => {
        const pqueueImport = await simport('../node_modules/p-queue/dist/index.js');
        resolve(pqueueImport.default);
    });
};

const queue: PQueue = new ((sp(importPqueue) as any)())({ concurrency: 1 });
nchanged commented 3 years ago

I think for the output you're supposed to use some other tool. Not a bundler.

paxperscientiam commented 3 years ago

@charsleysa , perhaps you could create a plugin that leverages microbundle?