What Are "npm run dev" and "npm run prod"

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Unveiling "npm run dev" and "npm run prod": Understanding Laravel Mix and npm Scripts Introduction: As a senior developer and technical blogger, I'm often asked about the relationship between popular web development tools and their usage in various scenarios. In this comprehensive post, let's delve into these two common commands: "npm run dev" and "npm run prod." We will explore what they do, their origins, as well as how to customize them within Laravel Mix, a powerful tool for managing front-end web assets in Laravel applications. An Overview of npm Commands: Firstly, let us understand the concept of scripts in Node Package Manager (npm) commands. Scripts are simply customizable tasks that can be run using various command combinations. These commands help automate repetitive processes within your project. For example, you could have one script for building and bundling assets (e.g., webpack) or another script for cleaning up the application's directories. Custom Laravel Mix Commands: Now that we know npm scripts are customizable commands, let us look at our specific use cases: "npm run dev" and "npm run prod." These commands are part of the workflow in a modern Laravel application powered by Laravel Mix. Laravel Mix extends npm's functionality to provide a more streamlined experience for managing your front-end assets, including webpack configuration and Sass compilation among other tasks. The commands are primarily focused on compiling scripts. "npm run dev": - "dev" is a script that runs the "development" command (defined under "scripts" in Laravel's package.json file). - This command is responsible for compiling and processing assets during development with Webpack, while still allowing you to access the source files. - The command uses cross-env to specify NODE_ENV=development before running webpack.js. It also makes use of laravel-mix setup/webpack.config.js configuration file for better integration with Laravel Mix features like mix.webpackConfig(). "npm run prod": - The "prod" command runs the "production" script defined under the scripts section in package.json. - This command compiles and processes assets during production mode, optimizing them through minification to maximize performance while reducing file sizes. This includes minimization of CSS and JS files using plugins like cssnano or uglifyjs-webpack-plugin. - Similar to the development mode, cross-env configures NODE_ENV=production before running webpack.js with custom Laravel Mix configuration. Customizing Scripts: By understanding where these scripts are defined and how they work, you can begin to modify them according to your application's needs. For example, if you want to add a new script like "npm run build," you could define it under the same scripts section in package.json file. This would allow you to create custom commands for any task related to asset management within your Laravel Mix-powered projects. Conclusion: Laravel Mix and npm-based scripts are powerful tools that streamline the web development process, simplifying tasks like compiling assets or managing environments. By understanding the relationship between "npm run dev" and "npm run prod," you can effectively leverage these commands in your Laravel applications and further customize them to suit your specific workflows. With this knowledge, you are one step closer to becoming an efficient web developer who maximizes their Laravel and npm experience.