I'm working on a Laravel project, and I'm trying to set up a build process using npm run build. However, when I attempt to run the command, I encounter the following error:
npm ERR! missing script: build
To address this, I added a build script to the scripts section of my package.json:
"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 --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",
"build": "webpack-cli app.tsx --config webpack-config.js"
},
When I run npm run build, I get the following error:
Error: Cannot find module 'webpack-config.js'
My Question:
How can I correctly configure webpack-config.js for a Laravel project? Is there a standard way to generate or create a webpack-config.js file that integrates with Laravel's setup, or should I be using a different approach for the build process?
Any guidance on how to properly set up the build script in Laravel's package.json would be greatly appreciated.
You will need to create a webpack-config.js in the same folder as your package.json file. You can find a webpack-config.js structure here https://webpack.js.org/configuration/