├── README.md ├── index.d.ts ├── index.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Mix - Merge Manifest 2 | 3 | This extension supports multi mix configration without overwriting the mix-manifest.json file. It merges new manifests into the existing one. 4 | 5 | ## Usage 6 | 7 | First, install the extension. 8 | 9 | ``` 10 | // Laravel Mix v5 11 | npm install laravel-mix-merge-manifest@v1 --save-dev 12 | 13 | // Laravel Mix v6 14 | npm install laravel-mix-merge-manifest@v2 --save-dev 15 | ``` 16 | 17 | Then, require it within your `webpack.mix.js` file, like so: 18 | 19 | ```js 20 | let mix = require('laravel-mix'); 21 | 22 | require('laravel-mix-merge-manifest'); 23 | 24 | mix 25 | .js('resources/assets/js/app.js', 'public/js') 26 | .less('resources/assets/less/app.less', 'public/css') 27 | .mergeManifest(); 28 | ``` 29 | 30 | ## Examples - Laravel Mix v6 31 | 32 | ### Running Laravel Mix with different configurations 33 | 34 | Laravel Mix only supports a global configuration. If you want to use diffent configurations - e.g. to provide a separate JS file for legacy browsers - you need to run mix multiple times with different configs. 35 | 36 | ```sh 37 | npx mix && npx mix --mix-config=webpack.legacy.mix.js 38 | ``` 39 | 40 | Your default configuration in `webpack.mix.js` could look like this: 41 | ```js 42 | // ... 43 | mix.js('resources/assets/scripts/main.js', 'scripts') 44 | .mergeManifest() 45 | // ... 46 | ``` 47 | 48 | And your legacy configuration in `webpack.legacy.mix.js` would use `.mergeManifest()`: 49 | ```js 50 | // ... 51 | mix 52 | .babel({ ... }) // Different Babel Configuration 53 | .js('resources/assets/scripts/main.js', 'scripts/main.legacy.js') 54 | .mergeManifest() 55 | // ... 56 | ``` 57 | 58 | 59 | ### Extracting multiple vendors 60 | 61 | ```sh 62 | npx mix --mix-config=webpack.backoffice.mix.js && npx mix --mix-config=webpack.customers.mix.js 63 | ``` 64 | 65 | `webpack.backoffice.mix.js` 66 | ```js 67 | mix 68 | .js('resources/js/backoffice/backoffice.js', 'public/js/backoffice') 69 | .extract(['jquery', 'bootstrap', 'lodash', 'popper.js']) 70 | .mergeManifest() 71 | ``` 72 | 73 | `webpack.customers.mix.js` 74 | ```js 75 | mix 76 | .js('resources/js/customers/customers.js', 'public/js/customers') 77 | .extract(['vue']) 78 | .mergeManifest() 79 | ``` 80 | 81 | Source: [How to Split Dependencies into Multiple Vendors using Laravel Mix](https://www.compulsivecoders.com/tech/how-to-build-multiple-vendors-using-laravel-mix/) 82 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | // Merge Manifest Api 2 | interface Api { 3 | /** Merges new manifests into the existing one */ 4 | mergeManifest(): Api; 5 | } 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | let mix = require('laravel-mix'); 3 | let ManifestPlugin = require('laravel-mix/src/webpackPlugins/ManifestPlugin'); 4 | let merge = require('lodash').merge; 5 | 6 | mix.extend('mergeManifest', (config) => { 7 | config.plugins.forEach((plugin, index) => { 8 | if (plugin instanceof ManifestPlugin) { 9 | config.plugins.splice(index, 1); 10 | } 11 | }); 12 | 13 | config.plugins.push(new class { 14 | apply(compiler) { 15 | 16 | compiler.hooks.emit.tapAsync('ManifestPlugin', (curCompiler, callback) => { 17 | let stats = curCompiler.getStats().toJson(); 18 | 19 | try { 20 | Mix.manifest.manifest = merge(Mix.manifest.read(), Mix.manifest.manifest); 21 | } catch (e) { 22 | 23 | } 24 | 25 | Mix.manifest.transform(stats).refresh(); 26 | callback(); 27 | }); 28 | } 29 | }) 30 | }); 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-mix-merge-manifest", 3 | "version": "2.1.0", 4 | "description": "A quick Laravel Mix extension to support multi mix configration without overwriting the mix-manifest.json file.", 5 | "main": "index.js", 6 | "types": "index.d.ts", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/kabbouchi/laravel-mix-merge-manifest.git" 13 | }, 14 | "keywords": [ 15 | "laravel", 16 | "laravel mix", 17 | "mix", 18 | "multi", 19 | "manifest" 20 | ], 21 | "author": "Georges KABBOUCHI", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/kabbouchi/laravel-mix-merge-manifest/issues" 25 | }, 26 | "homepage": "https://github.com/kabbouchi/laravel-mix-merge-manifest#readme", 27 | "dependencies": { 28 | "lodash": "^4.17.4" 29 | } 30 | } 31 | --------------------------------------------------------------------------------