Git Product home page Git Product logo

Comments (8)

evanw avatar evanw commented on May 23, 2024 4

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.

tracker1 avatar tracker1 commented on May 23, 2024 2

@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.

shunia avatar shunia commented on May 23, 2024 1

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.

evanw avatar evanw commented on May 23, 2024 1

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.

tracker1 avatar tracker1 commented on May 23, 2024

It'd be a bit more explicit/basic than say webpack, but at least allow for the flexibility.

from esbuild.

tracker1 avatar tracker1 commented on May 23, 2024

or maybe loaders instead of tranform

from esbuild.

maraisr avatar maraisr commented on May 23, 2024

Id love to see something like this - especially build time stuff to support tooling like Treat.

from esbuild.

abgier-avraha avatar abgier-avraha commented on May 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.