Comments (8)
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 --loader
flag. For example, to enable importing .yml
files as strings, you could pass --loader:.yml=text
to esbuild.
from esbuild.
@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 '.yml': require('esbuild-transform-plain-text'),
or similar... actually attaching what they want as their own transformers. expecting cwd to be the project/root.
from esbuild.
Without this I can not even just try how esbuild will work on my projects. Lots of required
file path to be dynamic loaded (json, png, jpg, etc.).
from esbuild.
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.
Or should file operations just occur within the loader switch case under parseFile?
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 parseResult
, then have the bundler emit instructions for file copy operations somehow.
Do you know how you would want to go about configuring the packaging of asset files?
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.
you would probably want a configuration file
The way to do this with esbuild is to invoke the bundle()
API from a JavaScript file. That takes the same options as the command-line tool but as a JavaScript object literal, like a configuration file.
from esbuild.
It'd be a bit more explicit/basic than say webpack, but at least allow for the flexibility.
from esbuild.
or maybe loaders
instead of tranform
from esbuild.
Id love to see something like this - especially build time stuff to support tooling like Treat.
from esbuild.
@evanw I was playing around with a loader I made that packages assets and gives them a unique name under /assets
in the bundle directory but I had to first add a property the parseResult
struct which to provide an optional output path for asset files. I figured that the loaders should determine whether they need to output any files or not.
After a file is parsed, I commit the file operations to copy over the assets within the ScanBundle
function according the to asset loader's parse results. Or should file operations just occur within the loader switch case under parseFile
? If so then there doesn't need to be any modifications to the parseResult
struct.
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 .jpg
, .png
, .svg
, .mp4
, .webm
by default. But you would probably want a configuration file for the user to configure which loader they want, correct? They can still do it via command line but I can see this becoming too much for a command.
from esbuild.
Related Issues (20)
- Running esbuild under npm explore no longer works HOT 1
- esbuild not work well with package.json has "exports:{"./*": "./*"}" HOT 2
- Allow destructuring for all target environments HOT 1
- re-create package.json with only externalized dependencies
- SyntaxError: The requested module X does not provide an export named Y since code modification HOT 1
- Cross-Platform Development Problem HOT 6
- CSS media query range syntax not downleveled
- Object rest and function scope HOT 4
- DCE doesn't remove unreferenced `new Regexp`. HOT 1
- CVE-2023-45288 HOT 3
- Throwing an error within a plugin does not stop the build
- Metafile not output to the `outdir` HOT 2
- Output is incorrect when there is an import declaration with an import clause that has one type only import specifier HOT 3
- invalid code generation HOT 3
- Building on top of esbuild Analyze HOT 1
- Strategy to determine visiting browser's inclusion or exclusion from the esbuild bundle target? HOT 3
- Incorrect import order causes errors HOT 2
- Feature request: Implement the Decorator Metadata proposal HOT 3
- ES Decorators no binding to `this`
- Missing `es2023` target HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esbuild.