├── .gitignore ├── CHANGELOG.md ├── .editorconfig ├── package.json ├── LICENSE.md ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | yarn-error.log 4 | /yarn.lock 5 | example/public 6 | example/mix-manifest.json 7 | .idea 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-mix-brotli` will be documented in this file 4 | 5 | ## 1.0.0 - 2019-09-18 6 | - Tested in Production 7 | 8 | ## 0.1.0 - 2019-09-18 9 | - Initial release 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [{package.json}] 15 | indent_size = 2 16 | 17 | [*.md] 18 | trim_trailing_whitespace = false 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-mix-brotli", 3 | "version": "1.0.0", 4 | "description": "A wrapper around brotli-webpack-plugin for Laravel Mix", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/ndberg/laravel-mix-brotli.git" 9 | }, 10 | "keywords": [ 11 | "laravel-mix", 12 | "brotli" 13 | ], 14 | "author": "Andreas Berger", 15 | "contributors": [], 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/ndberg/laravel-mix-brotli/issues" 19 | }, 20 | "homepage": "https://github.com/ndberg/laravel-mix-brotli", 21 | "dependencies": { 22 | "brotli-webpack-plugin": "^1.1.0" 23 | }, 24 | "devDependencies": {}, 25 | "peerDependencies": { 26 | "laravel-mix": "^4.0.0" 27 | }, 28 | "engines": { 29 | "node": ">=6.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) ndberg Andreas Berger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # brotli for Laravel Mix 2 | 3 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 4 | [![Latest Version on NPM](https://img.shields.io/npm/v/laravel-mix-brotli.svg?style=flat-square)](https://npmjs.com/package/laravel-mix-brotli) 5 | [![npm](https://img.shields.io/npm/dt/laravel-mix-brotli.svg?style=flat-square)](https://www.npmjs.com/package/laravel-mix-brotli) 6 | 7 | A wrapper around brotli-webpack-plugin for Laravel Mix. 8 | 9 | ```js 10 | let mix = require('laravel-mix'); 11 | require('laravel-mix-brotli'); 12 | 13 | // ... 14 | 15 | mix.js('resources/js/app.js', 'public/js') 16 | .sass('resources/sass/app.scss', 'public/css') 17 | .brotli(); 18 | ``` 19 | 20 | ## Installation 21 | 22 | Before you get started, make sure you're using `laravel-mix` version 4 or higher. 23 | 24 | You can install the package with yarn or npm: 25 | 26 | ```bash 27 | yarn add laravel-mix-brotli 28 | ``` 29 | 30 | ```bash 31 | npm install laravel-mix-brotli 32 | ``` 33 | 34 | Then install the extension by requiring the module in your Mix configuration. 35 | 36 | ```js 37 | let mix = require('laravel-mix'); 38 | require('laravel-mix-brotli'); 39 | 40 | // ... 41 | ``` 42 | 43 | brotli can then be enabled by calling `.brotli()` in your Mix chain. 44 | 45 | ```js 46 | mix.js('resources/js/app.js', 'public/js') 47 | .sass('resources/sass/app.scss', 'public/css') 48 | .brotli(); 49 | ``` 50 | 51 | Custom options can be passed when calling brotli if necessary. 52 | 53 | ```js 54 | mix.js('resources/js/app.js', 'public/js') 55 | .sass('resources/sass/app.scss', 'public/css') 56 | .brotli({ 57 | enabled: mix.inProduction(), 58 | asset: '[path].br[query]', 59 | test: /\.(js|css|html|svg)$/, 60 | threshold: 10240, 61 | minRatio: 0.8 62 | }); 63 | ``` 64 | 65 | ### Changelog 66 | 67 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 68 | 69 | ## Contributing 70 | 71 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 72 | 73 | ## License 74 | 75 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 76 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix'); 2 | var BrotliPlugin = require('brotli-webpack-plugin'); 3 | 4 | class LaravelMixBrotli { 5 | /** 6 | * The optional name to be used when called by Mix. 7 | * Defaults to the class name, lowercased. 8 | * 9 | * Ex: mix.example(); 10 | * 11 | * @return {String|Array} 12 | */ 13 | name() { 14 | return ['brotli']; 15 | } 16 | 17 | /** 18 | * All dependencies that should be installed by Mix. 19 | * 20 | * @return {Array} 21 | */ 22 | dependencies() { 23 | return ['brotli-webpack-plugin']; 24 | } 25 | 26 | /** 27 | * Register the component. 28 | * 29 | * When your component is called, all user parameters 30 | * will be passed to this method. 31 | * 32 | * Ex: register(src, output) {} 33 | * Ex: mix.yourPlugin('src/path', 'output/path'); 34 | * 35 | * @param {*} ...params 36 | * @return {void} 37 | * 38 | */ 39 | register(options = {}) { 40 | this.options = Object.assign( 41 | { 42 | enabled: mix.inProduction(), 43 | asset: '[path].br[query]', 44 | test: /\.(js|css|html|svg)$/, 45 | threshold: 10240, 46 | minRatio: 0.8 47 | }, 48 | options 49 | ); 50 | } 51 | 52 | /** 53 | * Boot the component. This method is triggered after the 54 | * user's webpack.mix.js file has executed. 55 | */ 56 | boot() { 57 | 58 | } 59 | 60 | /** 61 | * Plugins to be merged with the master webpack config. 62 | * 63 | * @return {Array|Object} 64 | */ 65 | webpackPlugins() { 66 | if (!this.options.enabled) { 67 | return; 68 | } 69 | 70 | return new BrotliPlugin(this.options); 71 | } 72 | 73 | /** 74 | * Override the generated webpack configuration. 75 | * 76 | * @param {Object} webpackConfig 77 | * @return {void} 78 | */ 79 | webpackConfig(webpackConfig) { 80 | // Example: 81 | // webpackConfig.resolve.extensions.push('.ts', '.tsx'); 82 | } 83 | } 84 | 85 | mix.extend(['brotli'], new LaravelMixBrotli()); 86 | --------------------------------------------------------------------------------