I am creating a typescript library, and when I am bundling it with parcel.js, the package.json
file is not getting copied into the dist
folder. Can any one let me know how can it be done?
You could accomplish this by using the copyfiles package and modifying your build script to copy the package.json
file to the dist
folder after parcel runs. (e.g. parcel build && copyfiles package.json dist
).
However, the reason why parcel doesn't support this out of the box is that you probably don't want to do this. When you're making and publishing an npm library, there are a number of fields in your package.json
that have special meaning - especially "main"
, but also "types"
and "module"
. When you publish your library, you want to make sure that these fields point to the right thing.
When you run parcel build
, parcel looks at these these fields in your package.json
to decide where to put the output files.
So if you then copied your unmodified package.json
file to the dist
folder and tried to publish the dist
folder as if it were your package, things would be broken for your users - the package.json
's main
field would point to dist/outputbundle.js
, but the actual file would be at /bundleoutput.js
.
If you want publish only a subset of the files in your project, the typical way to do this is to use the package.json
files
field to "whitelist" which folders get included when you run npm publish
, without modifying the package structure (see docs).