Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entryPoints does not support glob patterns #381

Closed
dwelle opened this issue Sep 11, 2020 · 7 comments
Closed

entryPoints does not support glob patterns #381

dwelle opened this issue Sep 11, 2020 · 7 comments

Comments

@dwelle
Copy link

dwelle commented Sep 11, 2020

Glob patterns in entryPoints are not supported:

const { build } = require('esbuild');
build({
  entryPoints: './src/*.ts',
  /* ... */
});

throws:

error: Duplicate entry point "../../../../../.."
error: Duplicate entry point "."
error: Duplicate entry point "s"

When specified as an array (entryPoints: ["./src/*.ts"]), it throws:

error: Cannot read file "src/*.ts"
@rtsao
Copy link
Contributor

rtsao commented Sep 11, 2020

You could always do something like this:

const { build } = require("esbuild");
const glob = require("tiny-glob");

(async () => {
  let entryPoints = await glob("./src/*.ts");
  await build({
    entryPoints,
    /* ... */
  });
})();

@dwelle
Copy link
Author

dwelle commented Sep 11, 2020

I know. I just thought it should either be 1) supported 2) handled (display user-friendly error) & documented.

@evanw
Copy link
Owner

evanw commented Sep 11, 2020

The reason why this looks so weird here is that entryPoints is supposed to be an array of strings:

entryPoints?: string[];

Passing a string instead causes esbuild to iterate over the characters in the string and treat each character as an entry point path. I will add an error for this case if you pass invalid data for the entryPoints array.

@dwelle
Copy link
Author

dwelle commented Sep 11, 2020

True (oh the joys of writing plain JS files instead of TS). I actually started with an array, and the error there is at least readable :).

@kuba-orlik
Copy link

You could always do something like this:

const { build } = require("esbuild");
const glob = require("tiny-glob");

(async () => {
  let entryPoints = await glob("./src/*.ts");
  await build({
    entryPoints,
    /* ... */
  });
})();

This solution is far from perfect, as it doesn't require new files - that is, files created after watch has been started

@allomov
Copy link

allomov commented Nov 27, 2022

Thank you! It was also acceptable to me to use resolve-glob with glob.sync, like this:

const glob = require('resolve-glob');

const options = {ignore: ["**/*.test.js", "**/*.spec.js", "**/*.stories.js"]};
const entryPoints = glob.sync(
  [
    "./app/javascript/**/*.ts",
    "./app/javascript/**/*.tsx",
    "./app/javascript/**/*.js",
    "./app/javascript/**/*.jsx"
  ],
  options)

build({
  entryPoints: entryPoints,
  // ...
}).catch(() => process.exit(1))

@ngdangtu-vn
Copy link

ngdangtu-vn commented Jun 11, 2023

Do we have any solution for CLI version guys?

Update

I didn't expect solution for bash shell would be this simple

esbuild $(find src/js -name *.js) --watch \
    --outdir=dist --outbase=src/js --target=es6 --format=esm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants