Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to run `npm run prod` on production?

Tags:

npm

laravel

Laravel ships with a package.json file for npm.

The default package.json only ships with devDependencies.

If I am not mistaken then:

  • npm run development is used to bundle all dependencies with web pack into a single file on local developent, which is then pushed via version-control to production.
  • npm install is only required on production, when package.json contains actual dependencies (and not only devDependencies).

However, I am a bit confused about the npm run production script. Should I run webpack in production? Or is this obsolete if I have done this in development and pushed it via VC? I did not find anything in the Deploy docs from Laravel.

like image 278
Adam Avatar asked Nov 26 '19 19:11

Adam


People also ask

Do I need to run npm run build every time I made changes?

Nope, Anything you change over code, build will rerun for that change.

Do I need to run npm install before build?

npm install installs dependencies into the node_modules/ directory, for the node project you're working on. You can call install on another node. js project (module), to install it as a dependency for your project. npm run build does nothing unless you specify what "build" does in your package.

What is npm install -- production?

By default, npm install will install all modules listed as dependencies in package. json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .

What does npm need to run?

Npm run has nothing to do with the node child process if that is what you are asking. Npm run is a command provided by npm CLI which allows to instantiate a shell and execute the command provided in the package. json file of your project. Now if you execute npm run test , npm will simply go and check in package.

What is the difference between NPM install and NPM run development?

npm run development is used to bundle all dependencies with web pack into a single file on local developent, which is then pushed via version-control to production. npm install is only required on production, when package.json contains actual dependencies (and not only devDependencies ).

What is NPM run Dev command?

The npm run dev command is a generic NPM command that you can find in many modern web application projects. This command is used to run the dev script defined in the project’s package.json file. To know what is exactly being run by the command, first you need to open the package.json file.

Is it possible to run composer and NPM commands on prod?

I don't see any issues with running the composer and npm command on prod. The only issue would be that it would cause an increase in load but in most cases that won't cause any problems. Ideally you would have a CI server that handles the build process though.

What is the difference between NPM run and run-script?

npm: One could say that it is a command native to the system, for calling Node Package Manager program. In Windows, for example, it should be the default command for calling npm from any console. run: It is a command native to npm. More information here. Keep in mind this is an aliases to the original command run-script.


1 Answers

What I usually do is use npm run dev or npm run watch which just watches for changes and still does development compiling, which means any console.log that I use, and the output is not minified, so this is good for development purposes as the scripts says :) . Before I push to production I ran npm run prod which then minifies the output and I version the output for caching purposes:

https://laravel.com/docs/master/mix#versioning-and-cache-busting

And I forgot to mention about the installing part.. if you run npm install on production it will install the devDependencies as well. So check this answer

https://stackoverflow.com/a/9276112/1457270

like image 104
nakov Avatar answered Oct 17 '22 07:10

nakov