Resolving multiple package.json "main" fields
**TL;DR:** A new compiler option `mainFields` for selecting multiple fields in `package.json` instead of just `package.json#main`. --- There are lots of related issues to this one (which I link to below), but I want to focus on just this specific proposal. --- Packages often look like this: ```js { "name": "my-package", "main": "dist/cjs/index.js", "module": "dist/esm/index.js" "source": "src/index.ts" } ``` Notice how we have multiple fields which specify multiple entry points. These entry points all refer to the same code, just in different compile states and configurations. Many tools use these fields in order to find the entry point that they care about. For example, tools like Webpack and Rollup will use `package.json#module` in order to find ES modules. Other tools will use fields like `package.json#source` (or `src`) for local package development. While these fields aren't part of the official Node module resolution algorithm. They are a community convention which has proven to be useful in lots of scenarios. For TypeScript, one such scenario that this would be useful for is with multi-package repos or "monorepos". These are repositories where the code for multiple npm packages exist and are symlinked together locally. ``` /project/ package.json /packages/ /package-one/ package.json /node_modules/ /package-two/ -> ../../package-two (symlink) /package-two/ package.json ``` Inside each package, you'll generally hav
Posted by jamiebuilds on Jan 26, 2018, 9:47 AM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (E-commerce)
proposal: cmd/cgo: cgo without a C toolchain
Replace PowerToys Run with Command Palette
VPS with a vRack leg
Possibility of Portal 1 Code Inclusion
Introducing NewPlayer
Metrics for PRs are never expiring ("memory leak")
ship even more of the compiler in source form
Flatpak Application TRACKING ISSUE
Resolving multiple package.json "main" fields
**TL;DR:** A new compiler option `mainFields` for selecting multiple fields in `package.json` instead of just `package.json#main`. --- There are lots of related issues to this one (which I link to below), but I want to focus on just this specific proposal. --- Packages often look like this: ```js { "name": "my-package", "main": "dist/cjs/index.js", "module": "dist/esm/index.js" "source": "src/index.ts" } ``` Notice how we have multiple fields which specify multiple entry points. These entry points all refer to the same code, just in different compile states and configurations. Many tools use these fields in order to find the entry point that they care about. For example, tools like Webpack and Rollup will use `package.json#module` in order to find ES modules. Other tools will use fields like `package.json#source` (or `src`) for local package development. While these fields aren't part of the official Node module resolution algorithm. They are a community convention which has proven to be useful in lots of scenarios. For TypeScript, one such scenario that this would be useful for is with multi-package repos or "monorepos". These are repositories where the code for multiple npm packages exist and are symlinked together locally. ``` /project/ package.json /packages/ /package-one/ package.json /node_modules/ /package-two/ -> ../../package-two (symlink) /package-two/ package.json ``` Inside each package, you'll generally hav
Comments (0)
No comments yet. Start the discussion.