I am very new in Laravel and vue.js.Please let me know what is the difference between npm run dev
and npm run production
.Is this something related with the environment?
The name of the scripts themselves is user-defined inside the package. json file. This means that npm run dev will run the dev command, while npm run production will run the production command. This means that npm will execute the next dev command when you call the npm run development command.
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 ).
TL;DR: In Next. js, next dev is used to run the app in development mode. On the other hand, next start is used to run the app in production mode, but requires next build to be run first to generate an optimized production 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.
npm run dev
creates a source map and doesn't minify your js/css which makes it easier to debug and find errors out
npm run production
on the other hand does not create a source map and minifies all your js/css files so that they are ready for production and are faster to read by the system.
Generally you would want to use npm run dev
when you're developing the site, and npm run production
when it's ready to be deployed.
Those are aliases defined on the package.json
to execute scripts
Here are the aliases and respective commands with parameters.
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"
},
We see two differences in parameters between two commands here
for dev/development it is
NODE_ENV=development --progress
While for production it is
NODE_ENV=production --no-progress
This means when dev command is run the node environment is set to development and when prod is run node environment is set to production. Additionally progress is not shown in production while shown on development command.
The default tasks will be different based on the environment. Also you can use it to customize your own tasks on webpack.mix.js
file something like this
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
//run this task if the environment is not in production
if(!mix.inProduction()) {
mix.sourceMaps();
mix.webpackConfig({ devtool: 'inline-source-map'})
}
Webpack
The actual difference between development and production is optimization. For production the build time will be more compared to development as some optimization tasks will be done only for production, this will minify the code as well. In Laravel by default Laravel mix is used to configure it easily. The underlying is handled by webpack. From the webpack documentation here you can check actually what are the differences between two environments and environment specific tasks.
Build performance develpment vs production
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With