First, npm run dev
should only be used for development. You should not push those files to production. It can be really slow, but it provides mayn development features like source maps, hot module replacement or debugging tools. The focus is on providing a convenient and efficient development experience rather than optimizing for performance.
The command npm run prod
will compress your js/css files, remove comments, and exclude development-specific features or config.
On local development you need to install all dependencies like this:
npm install
npm run dev
When working with Vue I usually call npm run hot
instead of npm run dev
so changes take effect without the need to refresh the page.
What most recommend here is to call
npm run prod
and then add those files to git and move to production server.
While this works, it will be messy because git control always shows you a lot of changed files in your public directory when you run npm run dev
although these changes should not be commited. Its also a risk that you accidentally commit dev files instead of prod files. Also its a pain for the developer to run npm run prod
every time he changes in the fron-end before the commit.
Thus, I prefer to gitignore my public directory, meaning I don't track those files with git at all. Instead, I run npm install --production
and npm run prod
to scaffold all files on my CI to production. You should make sure though, that you have a zero downtime deploy script, as the process of installing production js/css may take time if you have to install npm dependecies (see https://deployer.org/). The folder node_modules
can be removed after npm run prod
is finished.