lumeland/lume

Can't use `outfile` in the ESbuild plugin configuration

benjamingeets opened this issue · 3 comments

Version

2.3.0

What steps will reproduce the bug?

Install the ESbuild plugin & define outfile this way:

import lume from "lume/mod.ts";
import esbuild from "lume/plugins/esbuild.ts";

const site = lume();

site.use(esbuild({
    options: {
        outfile: 'app.js'
    }
}))

export default site;

What is the expected behavior?

Should use the outfile

What do you see instead?

[ERROR] Cannot use both "outfile" and "outdir".

Additional information

Seems logic however because the default ESbuild plugin configuration includes an outdir, but I don't think its possible to overwrite it.

(Tried to pass it false or undefined but dind't work, its expecting a string)

In Lume, the files are typically loaded, transformed and saved. And the esbuild plugin does some automatic configuration to follow this rule.

For example, if you have two typescript files:

/scripts/
    one.ts
    two.ts

The esbuild plugin transform the two files and save them with the same name but the .js extension:

/scripts/
    one.js
    two.js

In other words: esbuild plugin generate as many files as were found in the source folder.
If you only want to generate one file, make sure that Lume only load one file. For example, you can create a main.ts file that imports the other modules. If you do that, make sure that Lume only load the main file, by ignoring the other modules. A way to do that is with site.ignore() function or simply prefixing the scripts folder with an underscore:

/main.ts
/_scripts/
    one.js
    two.js
// main.ts

import "./_scripts/one.ts";
import "./_scripts/two.ts";

In this way, the plugin only uses main.ts as the entry point and the rest of the dependencies are bundled in that file.

Oh, OK, thank you for this explaination. In this cas, perhaps should we remove the outfile property of the ESbuild plugin doc page?

yep, that's a good point. I will.