Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the "files" property necessary in 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?

like image 225
ᅙᄉᅙ Avatar asked Jun 16 '16 10:06

ᅙᄉᅙ


People also ask

Is Main necessary in package json?

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.

What is main property in package json?

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.

Can I add custom properties to package json?

Yes, you're allowed to add custom entries to package. json .

Is it necessary to include all files in a JSON package?

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.

What should be in a JSON config file?

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.

How to add all files in a package in NPM?

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.

What does “include in your project” mean?

"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.


2 Answers

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 files

Both options are useful in different scenarios in my mind.

like image 158
F Lekschas Avatar answered Oct 25 '22 05:10

F Lekschas


Not really, you can do everything using .npmignore because all files are added unless otherwise stated.

You can see more here

like image 33
emilioriosvz Avatar answered Oct 25 '22 06:10

emilioriosvz