Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- Simple, fast routing engine.
- Powerful dependency injection container.
- Multiple back-ends for session and cache storage.
- Expressive, intuitive database ORM.
- Database agnostic schema migrations.
- Robust background job processing.
- Real-time event broadcasting.
Laravel is accessible, powerful, and provides tools required for large, robust applications.
Laravel has the most extensive and thorough documentation and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
If you don't feel like reading, Laracasts can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel Patreon page.
- Vehikl
- Tighten Co.
- Kirschbaum Development Group
- 64 Robots
- Cubet Techno Labs
- Cyber-Duck
- Many
- Webdock, Fast VPS Hosting
- DevSquad
- OP.GG
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the Laravel documentation.
In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [email protected]. All security vulnerabilities will be promptly addressed.
The Laravel framework is open-sourced software licensed under the MIT license.
Though Laravel Mix is optimized for Laravel usage, it may be used for any type of application. Begin by installing Laravel Mix through NPM or Yarn, and then copying the example Mix file to your project root.
mkdir my-app && cd my-app
npm init -y
npm install laravel-mix --save-dev
cp node_modules/laravel-mix/setup/webpack.mix.js ./
You should now have the following directory structure:
node_modules/
package.json
webpack.mix.js
The webpack.mix.js file is your configuration layer on top of webpack. Most of your time will be spent here.
Head over to your webpack.mix.js file:
const mix = require('laravel-mix');
mix.js('src/app.js', 'dist')
.sass('src/app.scss', 'dist')
.setPublicPath('dist');
Take note of the source paths. You're free to amend the paths to match your preferred structure, but if you're happy with our defaults simply run the following command to create the files and directories:
mkdir src && touch src/app.{js,scss}
You're all set now. Compile everything down by running:
node_modules/.bin/webpack --config=node_modules/laravel-mix/setup/webpack.config.js
You should now see:
dist/app.css
dist/app.js
dist/mix-manifest.json (Your asset dump file, which we'll discuss later.)
mix.combine(['src', 'files'], 'destination');
mix.babel(['src', 'files'], destination);
mix.minify('src');
mix.minify(['src']);
If used properly, Laravel Mix and webpack should take care of all the necessary module bundling and minification for you. However, you may have some legacy code or vendor libraries that need to be concatenated and minified. Not a problem.
Consider the following snippet:
mix.combine(['one.js', 'two.js'], 'merged.js');
This will naturally merge one.js
and two.js
into a single file, called merged.js
. As always, during development, that merged file will remain uncompressed. However, for production (export NODE_ENV=production
), this command will additionally minify merged.js
.
If you need to concatenate JavaScript files that have been written in ES2015, you may update your mix.combine()
call to mix.babel()
. The method signature is identical. The only difference is that, after the files have been concatenated, Laravel Mix will perform Babel compilation on the result to transform the code to vanilla JavaScript that all browsers can understand.
mix.babel(['one.js', 'two.js'], 'merged.js');
Similarly, you may also minify one or more files with the mix.minify()
command.
mix.minify('path/to/file.js');
mix.minify(['this/one.js', 'and/this/one.js']);
There are a few things worth noting here:
- This method will create a companion
*.min.ext
file. So minifyingapp.js
will generateapp.min.js
. - Once again, the minification will only take place during a production build. (
export NODE_ENV=production
). - There is no need to call
mix.combine(['one.js', 'two.js'], 'merged.js').minify('merged.js');
Just stick with the singlemix.combine()
call. It'll take care of both.