Skip to content

Instantly share code, notes, and snippets.

@croxton
Last active October 1, 2020 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croxton/5917f363891f2192be2984c511e27f4e to your computer and use it in GitHub Desktop.
Save croxton/5917f363891f2192be2984c511e27f4e to your computer and use it in GitHub Desktop.
Laravel Mix 4.x standalone installation instructions

First make sure you are using the latest stable version of Node.js. These intructions were tested with 11.9.0.

Setup a new project with Laravel Mix:

mkdir my-app && cd my-app
npm init -y
npm install laravel-mix --save-dev
cp node_modules/laravel-mix/setup/webpack.mix.js ./

Take a look at webpack.mix.js and see if you want to change any of the paths to your src and dist. Then create some initial source files:

mkdir src && touch src/app.{js,scss}

Run an initial compile and check that your build files are created as expected:

node_modules/webpack/bin/webpack.js --config=node_modules/laravel-mix/setup/webpack.config.js

As that's a bit verbose for everyday use, add these workflow scripts to 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": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
  "hot": "cross-env NODE_ENV=development webpack-dev-server --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 --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
}

You need the cross-env module to be installed to use the scripts above. To install globally:

sudo npm install --global cross-env

Now run your desired workflow, e.g.:

npm run dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment