-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Feature] Support references to non-js assets #14
Comments
This isn't exactly what this issue describes, but in case it's useful: I've since implemented a feature where you can load an arbitrary file type as a string using the |
@evanw that's a decent first step... however I do think that transformers and some sort of esbuild.config.js in the cwd would be prudent for specifying these things... namely setting up a transformer for a file type. // esbuild.config.js
const fs = require('fs');
module.exports = {
transforms: {
'.yml': filePath => Promise.resolve(fs.readFileSync(filePath, 'utf8'))
},
} Where each definition is a file extension, and the value is a function, or async function... if a promise/thenable is returned, wait for the result and use it, or blow up if rejected? From here, one could just |
It'd be a bit more explicit/basic than say webpack, but at least allow for the flexibility. |
or maybe |
Id love to see something like this - especially build time stuff to support tooling like Treat. |
Without this I can not even just try how esbuild will work on my projects. Lots of |
@evanw I was playing around with a loader I made that packages assets and gives them a unique name under After a file is parsed, I commit the file operations to copy over the assets within the Do you know how you would want to go about configuring the packaging of asset files? What I currently have is a an asset loader that packages common files like |
Heads up that I'm currently in the middle of a rewrite of the bundler to support tree shaking, ES6 modules, and code splitting. So now might not be the best time to consider contributing to the bundler.
The file system is deliberately abstracted away from the bundler to make it easy to test, and also to make it easy to run in API mode without touching the file system. Any necessary information to complete the operation should be added to the bundle and made available for tests to inspect, but the actual file operations should only be done after bundling is complete. I assume you'd have to attach some extra information to
If loaders need configuration information, I'd like for that to be provided in a consistent way for all loaders, not just for asset files. I haven't decided how that will work yet since no loaders currently need configuration.
The way to do this with esbuild is to invoke the |
Even if not supporting the likes of CSS transforms (sass/less), it would be nice if you added support for referencing static assets like images, etc. Can simply hold a reference, and output to the dist directory with originalname.hash.ext ... and then put the output path into the JS... that output path should probably be configurable as well... such as / (default), or /assets via configuration, etc.
This is what a lot of bundlers are doing for most things. Inlining and (s)css support would probably be natural followup support.
The text was updated successfully, but these errors were encountered: