https://github.com/fandogh/laravel-multimix
Laravel-Mix helper for projects with complex & multi assets.
https://github.com/fandogh/laravel-multimix
asset bootstrap-rtl laravel mix modular multimix package rtl webpack2
Last synced: about 1 year ago
JSON representation
Laravel-Mix helper for projects with complex & multi assets.
- Host: GitHub
- URL: https://github.com/fandogh/laravel-multimix
- Owner: fandogh
- License: mit
- Created: 2017-03-26T09:43:02.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-26T14:25:42.000Z (about 5 years ago)
- Last Synced: 2025-04-15T16:35:41.197Z (about 1 year ago)
- Topics: asset, bootstrap-rtl, laravel, mix, modular, multimix, package, rtl, webpack2
- Language: JavaScript
- Homepage: https://fandogh.github.io/laravel-multimix
- Size: 161 KB
- Stars: 26
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-laravel - Laravel MultiMix - Laravel-Mix helper for projects with complex & multi assets. (Resources / Development Tools)
README
> [Laravel-Mix](https://github.com/JeffreyWay/laravel-mix) helper for projects with complex & multi assets.
## π₯ Getting started
Since [mix](https://laravel.com/docs/5.4/mix) introduced in laravel 5.4 it is recommended to use this package for laravel >= 5.4 projects only.
Install package:
```bash
# NPM
npm install --save-dev laravel-multimix
# YARN
yarn add --dev laravel-multimix
```
Open your `package.json` and replace ugly scrips section with this:
```json
{
"scripts": {
"mix": "node node_modules/laravel-multimix/bin/mix"
}
}
```
Then you can run your tasks with this single command:
```bash
# Usage syntax: npm mix [preset=dev] [package=app]
# Example: run preset hot (with package app)
npm mix hot
# Example: run preset watch on package bootstrap
npm mix watch bootstrap
```
### π Presets
presets are just different sets of flags and envs passed to webpack.
They are basically same as default laravel package.json commands.
**Available Presets**
- dev
- watch
- args: `--watch`
- poll
- args: `--watch --watch-poll`
- hot
- args: `--hot --inline`
- entry: `webpack-dev-server`
- production
- env: `production`
### π¦ Packages
Packages are optional and available via `MIX_PACKAGE` env. It will do nothing by default.
But is very useful when using with Utils.
The philosophy behind packages is to having separate assets with different build workflow.
This makes builds cleaner, faster and more efficient.
### π Utils
Laravel MultiMix exposes some utils constant and functions.
- **MIX_PACKAGE** : is same as package name argument
- **NPM** : is relative path to `node_modules`
- **VENDOR** : is relative path to `resources/assets/vendor`
- **output(package_name)**: generates path to public with this template: `public/assets/{package}/`
- **OUTPUT**: is output for current MIX_PACKAGE
See example below for better understanding.
### π Example
```js
// webpack.mix.js
const {mix} = require('laravel-mix');
const {MIX_PACKAGE, NPM, VENDOR, OUTPUT, output} = require('laravel-multimix');
/*
|--------------------------------------------------------------------------
| Bootstrap
| @package bootstrap
|--------------------------------------------------------------------------
*/
if (MIX_PACKAGE === 'bootstrap') {
// Bootstrap + RTL
// generates public/assets/bootstrap/bootstrap.css
mix.sass('resources/assets/sass/bootstrap.scss', OUTPUT).options({postCss: [require('postcss-rtl')()]});
}
/*
|--------------------------------------------------------------------------
| App
| @package app
|--------------------------------------------------------------------------
*/
if (MIX_PACKAGE === 'app') {
// JS
// generates public/assets/app/app.js
mix.js('resources/assets/js/app.js', OUTPUT).extract([
'jquery',
'nprogress',
'swiper',
]);
// CSS
// generates public/assets/app/app.css
mix.styles([
output('bootstrap') + 'bootstrap.css',
NPM + 'swiper/dist/css/swiper.min.css',
], OUTPUT + 'app.css');
}
```
## βοΈCommon Issues
**Reload watcher when webpack.mix.js file is udpdated**
See [#1](https://github.com/fandogh/laravel-multimix/issues/1)
## π‘ Former & Related projects
- [laravel-elixir-packager](https://github.com/pi0/laravel-elixir-packager)
- [laravel-elixir-rtl](https://github.com/pi0/laravel-elixir-rtl)
- [laravel-elixirx (deprecated)](https://github.com/pi0/laravel-elixirx)
## π License
The MIT License (MIT) - Copyright (c) 2017 Fandogh - Pooya Parsa