-
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
API: Allow input from memory for building #212
Comments
The esbuild CLI is literally implemented using the public Go API, so if you want to do something that the CLI does you should be able to just reference that. Here's the part where it takes input from stdin and dumps the output to stdout: // Read the input from stdin
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
logging.PrintErrorToStderr(osArgs, fmt.Sprintf(
"Could not read from stdin: %s", err.Error()))
return 1
}
// Run the transform and stop if there were errors
result := api.Transform(string(bytes), *transformOptions)
if len(result.Errors) > 0 {
return 1
}
// Write the output to stdout
os.Stdout.Write(result.JS) Where the input comes from is intentionally not part of the API. There are many different potential sources of input (stdin, file, network, output of another command, etc.) and I don't think it makes sense to encode all of that in the API itself. It's trivial to read the input string from stdin first, as shown in the code example above. |
Seems I was wrong: you can’t pass a file for bundling (not transforming) via stdin via the CLI. I guess you’ll also need an option to specify the file name. Or am I missing something? |
Ah, I see. What's the use case? I'm asking because bundling usually involves multiple files, but you could only really pass one file via stdin. I could see wanting an API where you could pass an array of multiple in-memory files to bundle. Perhaps that's what you meant by saying it's related to #139. The way I plan to address both of those requests is with the future plugin API. |
I'm looking at using ESBuild as a Hugo pipe stage. |
Let's reopen this one. |
Does this work with module resolution? Is it possible to provide all the files in memory and build them out into a single bundle? |
The build CLI allows to take input from stdin and dump the output to stdout. This doesn't seem to be possible using the (Go) API?
Possibly related to #139
The text was updated successfully, but these errors were encountered: