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

Loader: support files with multiple extensions #215

Closed
iamakulov opened this issue Jul 2, 2020 · 3 comments
Closed

Loader: support files with multiple extensions #215

iamakulov opened this issue Jul 2, 2020 · 3 comments

Comments

@iamakulov
Copy link

iamakulov commented Jul 2, 2020

Right now, the loader option doesn’t support matching by multiple extensions. For example:

// index.js
import moduleAsText from "./module.raw.js"
console.log(moduleAsText)
# Shell
$ esbuild --bundle index.js --outfile=out.js --loader:.raw.js=text
error: Invalid file extension: ".raw.js"
1 error

Would it be possible to support this?

Practical use-case: for me, this is needed for interop with webpack.

A team I’m working with is trying to switch to ESBuild for development, keeping webpack in production. In the codebase, there’re a few cases where a .js file is being loaded with raw-loader. In webpack, it’s possible to match these files with test: /\.raw\.js$/ and apply the loader selectively; but ESBuild throws an error.

@iamakulov iamakulov changed the title Loader: support files with multiple exceptions Loader: support files with multiple extensions Jul 2, 2020
@evanw
Copy link
Owner

evanw commented Jul 3, 2020

Yes, I've been planning to do this. A use case I have in mind for later is .css vs .module.css. The behavior that makes the most sense to me is for it to pick the loader with the longest match.

@evanw evanw closed this as completed in 9c1775e Jul 4, 2020
@anubra266
Copy link

@evanw I'm working on a project, where I'll like to import some of my .tsx components with the text loader in some cases. How could I go about this?

@iamakulov
Copy link
Author

iamakulov commented Jun 7, 2022

@anubra266 What I did in a similar case was renaming these files from something.tsx to something.raw.tsx and then assigning a text loader to the .raw.tsx extension:

esbuild --loader:.raw.tsx=text

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

3 participants