Thursday, 4 May 2017

npm: meaning of main attribute

npm init will generate a file named package.json. Here is the content:

{
  "name": "webpack-tut",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
   ....
}

I read on this package.json doc

The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.

This should be a module ID relative to the root of your package folder.

For most modules, it makes the most sense to have a main script and often not much else.

I don't really understand this. Because in my project and in some projects I have downloaded, it looks like this field is no effect. I change the file name, example: "main": "temp.js" and app still runs normal.



via Trần Kim Dự

No comments:

Post a Comment