Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does scripts "npm run dev" and "npm run watch" is used for?

Tags:

npm

vue.js

I'm new in vue, and a documentation says that every time I create a component I have to run npm run dev and npm run watch. But don't know what their purpose is? Can someone help me?

like image 551
sergioo Avatar asked Nov 05 '19 22:11

sergioo


People also ask

What is use of npm run watch?

npm run watch always keeps running. It will watch your files for changes. So if you for example make a change in resources/assets/js/app. js and save the file, it will compile again.

What is npm run script?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.

What is the difference between npm run dev and npm run serve?

npm run serve is basically asking the package manager (npm) to run the command specified under the name serve in the package. json file. The same goes for the npm run dev command. It is possible that both execute the same command or different things.

What is npm and npm script?

An npm script is a convenient way to bundle common shell commands for your project. They are typically commands, or a string of commands, which would normally be entered at the command line in order to do something with your application. Scripts are stored in a project's package.


1 Answers

npm run dev combines all your Vue components and other JavaScript files into a browser-friendly combined file.

npm run watch does the same, but then it stays active and "watches" for updates to your .vue and .js files. If it detects a change, it'll re-build the browser-friendly file so you can just refresh the page.

like image 97
ceejayoz Avatar answered Oct 11 '22 19:10

ceejayoz