It looks like the package will include all files (that are not ignored), even if the package.json
has no "files"
array.
Is that property necessary?
You only need a main parameter in your package. json if the entry point to your package differs from index. js in its root folder. For example, people often put the entry point to lib/index.
The main property of a package. json is a direction to the entry point to the module that the package. json is describing. In a Node. js application, when the module is called via a require statement, the module's exports from the file named in the main property will be what's returned to the Node.
Yes, you're allowed to add custom entries to package. json .
It looks like the package will include all files (that are not ignored), even if the package.json has no "files" array. Is that property necessary? Not really, you can do everything using .npmignore because all files are added unless otherwise stated.
It must be actual JSON, not just a JavaScript object literal. A lot of the behavior described in this document is affected by the config settings described in config. If you plan to publish your package, the most important things in your package.json are the name and version fields as they will be required.
If you look at npm's package.json, you'll see that it has directories for doc, lib, and man. In the future, this information may be used in other creative ways. If you specify a bin directory in directories.bin, all the files in that folder will be added.
"include in your project" means the files will be in the packaged tarball that is created when you run npm publish. You can also run npm pack to generate the tarball for inspection without actually triggering a publish. This way you can actually open the generated tarball and inspect which files were/were not included.
You can think of the files
property in package.json
as an allowlist of all files that should be included in a npm release and .npmignore
as a denylist of all files that should not be included.
As a rule of thumb, for my own projects I usually use:
files
when my project has lots of auxiliary files like build scripts, config files, etc., that do not need to be included in a npm release.npmignore
when there are only a few such auxiliary filesBoth options are useful in different scenarios in my mind.
Not really, you can do everything using .npmignore
because all files are added unless otherwise stated.
You can see more here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With