Flake output as npm dependency

I have a project with this structure

src
|- flake.nix
|- widget/
  |- Cargo.toml
  |- src/
|- frontend/
  |- package.json
  |- index.{html,js}

In flake.nix, I have a derivation where the contents of widget gets built into a wasm library, so if I run

nix build .#widget

it generates result/lib/widget.wasm along with some binding files such as package.json.

In frontend/, I have a javascript package and I want it to depend on this widget. package.json does not allow environment variables, so a solution like this would not work:

     devShells = {
        web = pkgs.mkShell {
          WIDGET_PKG = widget;
          buildInputs = [
            pkgs.nodejs
            pkgs.nodePackages.npm
          ];
        };
      };

package.json documentation about local urls

Is there a solution that would support both a dev shell in frontend/ and a flake output building the javascript package in frontend/?