Standard package.json key for .ts files
See original GitHub issueA common TypeScript module structure looks like this:
src/index.ts
dist/index.js
dist/index.d.ts
and a package.json
that looks like this:
"main": "dist/index.js",
"types": "dist/index.d.ts",
There’s a convention to use the package.json key jsnext:main
to point to a variant of main
that uses ES2015 module syntax. Can we develop a similar convention to point at .ts
files, e.g. typescript:main
?
Consider a TypeScript project that is sharded across many microlibraries (e.g. my-project-core
, my-project-thing-plugin
, my-project-other-thing-plugin
). I’d like to be able to configure my bundler to import from src/*.ts
files for any module whose name starts with my-project
. Otherwise, it will be looking in dist/*.js
and I’ll have to rebuild the plugins any time I make changes in them.
Of course, I could use jsnext:main
for this purpose now, but any consumers who aren’t using TypeScript would get syntax errors for any files that contained TS-specific syntax like types. Similarly, I could make up my own package.json key and configure my bundler to look there first, but it behooves the community to have a convention here. That will allow bundlers like Webpack, Browserify, Rollup, and Pundle to look in the right place by default.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:7 (3 by maintainers)
Top GitHub Comments
Side note (in case anyone else references the OP): the
types
field would usually point todist/index.d.ts
and notsrc
.@mhegazy Sharing sources is the only way to get around the problems listed in #35822.