Use Vite aliases to allow excluding commercial components

Open
#240 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, typescript, vite

Research direction

Start by tracing the direct component imports in index.js and the generated Vite configuration in vite.generated.ts, then inspect package.json and the publishing setup. The work is done when applications can omit commercial components and dependencies while the remaining imports resolve cleanly in Vite development and npm installation.

Written by the indexing model from the issue text.

Description

enhancement

The current implement is directly referencing all Vaadin components in react-components, regardless of the license of the component. This is problematic for users that are for some reason (e.g. government policy) required to only have open source dependencies in their application (in other words, it's not acceptable to have commercial dependencies even if those are not used). It is not practical to exclude specific components because of the way index.js directly imports all components. Tree shaking during the production build leaves out unused modules but Vite in dev mode will still try to load all the modules.

One way of solving this would be to configure Vite to have an alias for any missing dependency to replace that import with a dummy placeholder that just informs the user that the dependency was missing. We could make Vaadin's default Vite configuration (vite.generated.ts) check for the existence of each commercial web component dependency and include a corresponding alias in the Vite configuration if it's not present.

In addition to this, we also need to make it practical to exclude those dependencies on the npm level. One potential way for this is to have those web components as optional peer dependencies instead of regular dependencies. There has been some reports about version conflict issues in combination with peer dependencies so one alternative might to have a regular dependency in our own code but remove it from package.json when publishing the module to npm. In either case, we also need to have a separate dependency that applications should have in their package.json to explicitly include the optional components along with logic that automatically includes this dependency when com.vaadin:vaadin is on the classpath while not including it if only com.vaadin:vaadin-core is present.

Dominant language
TypeScript
Stars
18
Forks
4
Avg merge
52m
Merged PRs (30d)
7

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vaadin/react-components

All issues in vaadin/react-components

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.