Skip to content

How to use platforms and toolchains to distinguish between Node and Browser targets? #2073

@ajbouh

Description

@ajbouh

I am building a project that runs on both nodejs and in the browser. I need to use different implementations of a ts_library depending on the runtime environment.

This seems like a good fit for Bazel's platform concept, (in combination with ts_library's module_name argument), but I'm having trouble figuring out how to properly model this scenario.

Tools like webpack and rollup can be configured to look in the "browser" field of package.json to find an entry-point appropriate for the browser. I'd like to be able to accomplish the same in Bazel with rules_nodejs.

This project's README.md implies this should be possible but I can't find any guidance in the rest of the documentation on how to do it properly:

The nodejs rules integrate NodeJS development toolchain and runtime with Bazel.

This toolchain can be used to build applications that target a browser runtime ...

I've looked through the Bazel Platforms Cookbook but haven't seen anything there that would fit the bill.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Can Close?We will close this in 30 days if there is no further activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions