Very high memory consumption while building multiple vue apps with vue-loader

Hi,

We are using vue-loader (usually together with the html-webpack-plugin, but I omit this in the following because it is not the important part) to transpile multiple vue based applications within a single project. Our webpack configuration looks a little bit like the following:

const apps = [
  { html: 'app-1', js: 'app-1' },
  { html: 'app-2', js: 'app-2' },
  ...
]

module.exports = (_a, _b) =>({
  entry: Object.fromEntries(apps.map(app => [app.js, './src/${app.js}.js'])),
  ...
  plugins: [
    new VueLoaderPlugin()
  ],
  ...
})

So for instance, app-1.html has a div with id app, which is referenced in app-1.js:

import Vue from 'vue'
import App1 from './app-1.vue'
...
new Vue({...}).$mount('#app')

This means our directory structure (very simplified) looks like the following:

  • src
    • app-1.html
    • app-1.js
    • app-1.vue
    • app-2.html
    • app-2.js
    • app-2.vue
  • package.json
  • webpack.config.js

Now here is our problem: We noticed a very high memory consumption, which increases drastically the more apps we have in our apps array. This is something like > 10 GB for a project containing 8 of these apps.

Could this be something like a memory leak in the vue-loader or are we somehow misusing the plugin? We are using version 15.10.0 of vue-loader.

Thank you and best regards

Nils

PS: If necessary I can provide a complete example to show our issue.

Hi,

It seems that vue-loader was not the culprit. I can reproduce the same high memory consumption when I remove the vue-loader completely and don’t use any plugins at all. It seems that the terser plugin (which is automatically used by webpack) is the one using up that much memory (see also https://github.com/webpack/webpack/issues/13550). By default terser spawns a lot of threads. One can control this behaviour:

const TerserPlugin = require("terser-webpack-plugin")
...

module.exports = {
    ...
    optimization: {
        minimize: true,
        minimizer: [
            new TerserPlugin({
                parallel: 2,
            })
        ]
    }
}

Alternative solution would be to use another minimizer, e.g. esbuild-loader.