How to include webpack plugins when using Laravel Mix? : <p>How should I include webpack plugins if I use WebPack AND Laravel Mix? I am confused which file I add the plugin code into.</p>

<p>My below attempt doesn't seem to be running my plugin. The plugin should be compressing the js, css files but its not.</p>

<p><code>webpack.config.js</code>:</p>

<pre><code>  require('./node_modules/laravel-mix/src/index');
  require(Mix.paths.mix());

  // My plugin is here
  const CompressionPlugin = require('compression-webpack-plugin');

  Mix.dispatch('init', Mix);

  let WebpackConfig = require('./node_modules/laravel-mix/src/builder/WebpackConfig');

  module.exports = new WebpackConfig({
     plugins: [
      new CompressionPlugin({
        asset: "[path].gz[query]",
        algorithm: "gzip",
        test: /\.js$|\.css$|\.html$|\.svg$/,
        threshold: 10240,
        minRatio: 0.8
      })
    ],
  }).build();
</code></pre>

<p><code>webpack.mix.js</code>:</p>

<pre><code>  let mix = require('laravel-mix');

  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
      })
  .version();
</code></pre>

<p>My NPM command is: </p>

<blockquote>
  <p>node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=webpack.config.js</p>
</blockquote>
