Mix’s API provides a useful webpackConfig method for adjusting the webpack config.
https://laravel.com/docs/5.6/mix#custom-webpack-configuration
The
webpackConfigmethod accepts an object, which should contain any Webpack-specific configuration that you wish to apply.
I believe the following code should work.
webpack.mix.js:
const mix = require('laravel-mix');
const CompressionPlugin = require('compression-webpack-plugin');
mix.setPublicPath('dist')
.js('src/app.js', 'scripts/')
.extract([
'jquery',
'axios',
'babel-polyfill',
'lodash',
'tether',
'vue',
'bootstrap-vue',
'vuex',
'vuex-localstorage',
])
.sass('src/styles/app.scss', 'styles/')
.copyDirectory('src/assets', 'dist/assets')
.options({
processCssUrls: false,
uglify: true,
})
.webpackConfig({
plugins: [
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$|\.svg$/,
threshold: 10240,
minRatio: 0.8,
}),
],
})
.version();