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

Include non-JS assets in esbuild bundles #2553

Closed
shosti opened this issue Mar 26, 2021 · 5 comments
Closed

Include non-JS assets in esbuild bundles #2553

shosti opened this issue Mar 26, 2021 · 5 comments
Labels
Can Close? We will close this in 30 days if there is no further activity enhancement

Comments

@shosti
Copy link

shosti commented Mar 26, 2021

🚀 feature request

Relevant Rules

  • esbuild
  • ts_library

Description

esbuild has the ability to load non-JavaScript assets such as CSS and binary files. It would be awesome if this were exposed to Bazel (if it is currently possible, I can't figure out a way).

Describe the solution you'd like

Probably the most intuitive way would be to include assets in the srcs or data section of ts_library. So if you had a main.tsx file that looked like:

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";

ReactDOM.render(<h1>Hello!</h1>, document.getElementById("root"));

with related CSS in index.css, the relevant rules could be something like:

ts_library(
    name = "lib",
    srcs = ["main.tsx"],
    data = ["index.css"],
    deps = [
        "@npm//react",
        "@npm//react-dom",
        "@npm//@types/react",
        "@npm//@types/react-dom",
    ],
)

esbuild(
    name = "bundle",
    entry_point = "main.tsx",
    deps = [
        ":lib",
    ],
    ...
)

(This setup currently produces an error like Could not resolve "./index.css".)

Describe alternatives you've considered

The only alternative I know of is to have CSS/other assets completely separate from the bundling pipeline, which seems less than ideal.

@mattem
Copy link
Collaborator

mattem commented Mar 26, 2021

I think this is partly covered by #2545, but it should handle pulling through the data dependencies

@mattem
Copy link
Collaborator

mattem commented Apr 8, 2021

output_css is now landed at HEAD via #2545. Will keep this open for the binary support if possible, haven't investigated yet.

@jaronsummers
Copy link

Is there a way to do this for a more general use case? I have a json file that is generated at build time, and I want it included as part of the ts_library outputs, and it's not entirely obvious to me how to do that. the naive approach of wrapping the ts_library in a filegroup doesn't seem to work, because ts_library's output is a struct with a number of expected attributes on it.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions bot added the Can Close? We will close this in 30 days if there is no further activity label Sep 14, 2021
@github-actions
Copy link

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? We will close this in 30 days if there is no further activity enhancement
Projects
None yet
Development

No branches or pull requests

3 participants