简体   繁体   English

什么是“npm run dev”和“npm run prod”

[英]What Are "npm run dev" and "npm run prod"

I use the following command to bundle my scripts via the Laravel Mix module:我使用以下命令通过 Laravel Mix 模块捆绑我的脚本:

npm run dev // Compile scripts.

npm run prod // Compile and minify scripts.

Are these native npm commands or custom Laravel Mix commands?这些是原生 npm 命令还是自定义 Laravel Mix 命令? Where are they defined?它们在哪里定义?

I noticed they are listed as "scripts" in the Laravel package.json.我注意到它们在 Laravel package.json 中被列为“脚本”。 What exactly are these scripts, custom commands for Webpack via Laravel Mix?这些脚本到底是什么,通过 Laravel Mix 为 Webpack 自定义命令?

"scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "npm run development -- --watch",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

They are indeed the scripts as defined in the package.json file as you discovered.它们确实是您发现的package.json文件中定义的脚本。 The values are run by your shell (so, for example, bash , zsh , etc. on UNIX-like operating systems).这些值由您的 shell 运行(例如,类 UNIX 操作系统上的bashzsh等)。

One key thing to note is that the node_modules/.bin directory is added to PATH before executing.需要注意的一个关键事项是node_modules/.bin目录在执行之前被添加到PATH So, in the case of the two scripts you're asking about, cross-env can be found in node_modules/.bin (because it's almost certainly specified as a devDependency elsewhere in the package.json ) as long as you've already run npm install or npm ci within the project directory.因此,在您询问的两个脚本的情况下,只要您已经运行,就可以在node_modules/.bin找到cross-env (因为几乎可以肯定它在package.json其他地方被指定为 devDependency ) npm installnpm ci在项目目录中。

Those commands are used at any project which supports JSON files on NPM.这些命令用于任何支持 NPM 上的 JSON 文件的项目。 Regarding OP questions:关于OP问题:

Are these native npm commands or custom Laravel Mix commands?这些是原生 npm 命令还是自定义 Laravel Mix 命令? Where are they defined?它们在哪里定义?

  • npm : One could say that it is a command native to the system, for calling Node Package Manager program. npm :可以说它是系统本机的命令,用于调用节点包管理器程序。 In Windows, for example, it should be the default command for calling npm from any console.例如,在 Windows 中,它应该是从任何控制台调用 npm 的默认命令。
  • run : It is a command native to npm. run :它是 npm 的原生命令。 More information here .更多信息在这里 Keep in mind this is an aliases to the original command run-script .请记住,这是原始命令run-script的别名。
  • dev and prod : They're user defined. devprod :它们是用户定义的。
    • dev : Used for running the specific commands for serving the project, to any server, to live development. dev :用于运行特定的命令来为项目提供服务,到任何服务器,以进行实时开发。 In the case of a web page, you'll see your web page in the browser, and any change you make to the HTML code, for example, will be reflected immediately in the page you see in your browser.对于网页,您将在浏览器中看到您的网页,例如,您对 HTML 代码所做的任何更改都会立即反映在您在浏览器中看到的页面中。
    • prod : Compiles all the necessary files for production. prod :编译生产所需的所有文件。 Final product.完成品。 In the case of a web page, for example, the HTML, CSS, and JS files you'll handle to the client.例如,在网页的情况下,您将处理给客户端的 HTML、CSS 和 JS 文件。 The result of running this command, it is expected to be one single folder with all the afore mentioned content.运行此命令的结果是一个包含所有上述内容的文件夹。

I noticed they are listed as "scripts" in the Laravel package.json.我注意到它们在 Laravel package.json 中被列为“脚本”。 What exactly are these scripts, custom commands for Webpack via Laravel Mix?这些脚本到底是什么,通过 Laravel Mix 为 Webpack 自定义命令?

  • "dev": "npm run development" : Runs the commandment immediately below, which is: "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" . "dev": "npm run development" : 运行下面的命令,即: "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" What this line of code does, depends on what dependencies you have on your project (see the node_modules folder, and read their respective documentation).这行代码的作用取决于您对项目的依赖关系(请参阅node_modules文件夹,并阅读它们各自的文档)。
  • "prod": "npm run production" : It has the same description than the item above, but for npm run prod "prod": "npm run production" : 它与上面的项目有相同的描述,但对于npm run prod

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

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