javascript - Why declare dependencies in dependencies?
为情所困
为情所困 2017-06-21 10:11:57
0
5
690

When you see the module installed by --save, it will be displayed in dependencies.
And the modules in dependencies represent the dependencies of the production environment. Such as jQuery.

But what I don’t understand is, take jQuery as an example. Why should I declare dependencies in dependencies?
In a production environment, I will directly use script tags to reference jQuery, without dependencies at all. What happens if the modules that the production environment depends on are declared in dependencies? Will it automatically add script tags for me or, for example, when packaging modules, when packaging production environment modules, will all dependencies in dependencies be packaged? But as far as I know, for example, when webpack modules are packaged, they are packaged based on the dependency graph created by the require module, so I don't quite understand why production environment dependencies should be declared in dependencies.

为情所困
为情所困

reply all (5)
我想大声告诉你

We will use many modules in actual development. Some modules (such as gulp, babel, these are placed in devDependencies) are only used in the development environment, while jquery is used in the production environment. When you deploy the project to In a production environment, if you execute npm install --production, only the modules in dependencies will be installed, which makes it very convenient to manage modules

    Ty80

    The fact is that that field is designed for node, so it doesn’t matter whether you write it or not.

    To be more specific, as a front-end project, your dependencies are either packaged or introduced with script tags, so what is in your deps field will not affect the final code at all.

      Peter_Zhu
      • If you use