简体   繁体   English

angular2 中的 package.json 是否需要以任何方式启动应用程序?

[英]Is package.json in angular2 needed in any way to start the application?

As I've read in numerous sources, package.json does not affect the start up of the angular2 application or any other applications (React.js app for example).Basically, package.json just provides information (also called as metadata which help developers to know what they have in their application, some kind of summary for the entire application nodules?正如我在众多来源中读到的那样, package.json不会影响 angular2 应用程序或任何其他应用程序(例如 React.js 应用程序)的启动基本上, package.json只提供信息(也称为元数据,有助于开发人员要知道他们在他们的应用程序中有什么,对整个应用程序结节的某种总结?

Is this correct what I've written?这是我写的正确吗?

I've tried to erase some lines and run the application without the entire package.json and the app starts successfully.我试图删除一些行并在没有整个package.json 的情况下运行应用程序,并且应用程序成功启动。

In react we had the webpack.config.js but I'm aware that in angular this is hidden and is not meant to be modified.在反应中,我们有webpack.config.js,但我知道在 angular 中这是隐藏的,不能修改。 However I feel more comfortable when seeing a file which is connected to the app build procedure rather than the background scene doing it for me (like in angular).但是,当看到连接到应用程序构建过程的文件而不是为我做的背景场景时,我感觉更舒服(比如在 angular 中)。

Can someone please elaborate and confirm if the above thesis are all correct?有人可以详细说明并确认上述论文是否全部正确?

package.json file is required. package.json文件是必需的。 It contain all the dependency(Dependency, DevDependency and peerDependency) with version for the angular project. 它包含角度项目版本的所有依赖项(Dependency,DevDependency和peerDependency)。

When you run npm install command then it will install all the node_modules listed under package.json. 当您运行npm install命令时,它将安装package.json下列出的所有node_modules。 So you need to transfer code from one PC to other PC then no need to transfer all node_modules you just need proper package.json file and run npm install command. 因此,您需要将代码从一台PC传输到另一台PC,然后无需传输所有node_modules,只需要正确的package.json文件并运行npm install命令。

Once you install all the dependency in your PC then application will start if you do any changes in this file. 在PC中安装所有依赖项后,如果您对此文件进行任何更改,则应用程序将启动。

It highly depends on the setup. 这在很大程度上取决于设置。

Neither Angular nor React require you to use a package.json or Webpack. Angular和React都不要求您使用package.json或Webpack。

As I've read in numerous sources, package.json does not affect the start up of the angular2 application or any other applications (React.js app for example). 正如我在众多来源中所读到的那样,package.json不会影响angular2应用程序或任何其他应用程序(例如React.js应用程序)的启动。

It depends. 这取决于。 If you use npm scripts or your build process requires the package.json file, then it is required. 如果您使用npm脚本或您的构建过程需要package.json文件,那么它是必需的。 Otherwise it is optional. 否则它是可选的。 Note, however, that using it is a best-practice in frontend and Node.js projects. 但请注意,使用它是前端和Node.js项目中的最佳实践。

Basically, package.json just provides information (also called as metadata which help developers to know what they have in their application, some kind of summary for the entire application nodules? 基本上,package.json只提供信息(也称为元数据,帮助开发人员知道他们在应用程序中有什么,对整个应用程序结节有什么样的总结?

This is correct. 这是对的。 The package.json file is also used when you want to publish your project to the npm package repository. 当您要将项目发布到npm包存储库时,也会使用package.json文件。

In react we had the webpack.config.js but I'm aware that in angular this is hidden and is not meant to be modified. 在反应中,我们有webpack.config.js,但我知道在角度中这是隐藏的,并不意味着要修改。

When you mention that the build process is "hidden" in Angular, I guess you are referring to the Angular CLI . 当你提到构建过程在Angular中被“隐藏”时,我猜你指的是Angular CLI You are correct, that Angular CLI uses Webpack behind the scenes. 你是对的, Angular CLI在幕后使用Webpack However, using the Angular CLI in an Angular project is completely optional and you can create your own build configuration. 但是,在Angular项目中使用Angular CLI是完全可选的,您可以创建自己的构建配置。

package.json initially is used to define a nodejs package, which can be then submitted to the npm and be installed by other people. package.json 最初用于定义一个 nodejs 包,然后可以将其提交到 npm 并由其他人安装。 It describe the basic info like name, version and dependency.它描述了基本信息,如名称、版本和依赖项。 Now you understand, your "project" is actually a package in a way, which needs dependency of course.现在你明白了,你的“项目”在某种程度上实际上是一个包,当然需要依赖。 It's like the requirement.txt in django project, can be used to store the dependency of this project, and to quickly build up the dev environment in case you change machine.就像django项目中的requirement.txt,可以用来存放这个项目的依赖,在换机时快速搭建dev环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM