Skip to content

Add exports field to package.json #212

@Niznikr

Description

@Niznikr

The problem
Webpack 5 module federation dependency sharing works best with imports from a package's root entry file. Currently to share Pharos, folks would need to list the individual components they'd like to share as their imports go deep into the package:

import '@ithaka/pharos/lib/components/modal/pharos-modal';

The solution
Address #3 and then add an exports field to the package.json to define the main entry point and encapsulate the package to prevent other entry points.

"exports": {
    ".": "./lib/index.js",
    "./lib": "./lib/index.js",
    "./lib/index": "./lib/index.js",
    "./lib/index.js": "./lib/index.js",
    "./package.json": "./package.json",
    "./custom-elements.json": "./custom-elements.json"
  }

The first entry would allow consumers to import component definitions in this way:

import { PharosButton } from '@ithaka/pharos';

Thus they would only need to add @ithaka/pharos as a shared dependency in their MFE configuration.

Alternatives considered
N/A.

Additional information
This will likely be a breaking change as only the entry points defined in the field would be allowed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions