Vue CLI's type checking service ignores memory limits

后端 未结 3 1806
忘掉有多难
忘掉有多难 2021-02-07 13:05

DevOps has requested that we limit our frontend builds to ~1GB of RAM, so that our Jenkins instance doesn\'t shut down. We use a standard @vue/cli project, with Typ

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-07 13:40

    I ran into the same issue (although in my case, I wanted to raise the memory limit instead of lower it). I was able to modify the configuration of the ForkTsCheckerWebpackPlugin by customizing Vue CLI's built-in webpack.config:

    // in vue.config.js
    
    const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
    
    module.exports = {
      configureWebpack: config => {
    
        // get a reference to the existing ForkTsCheckerWebpackPlugin
        const existingForkTsChecker = config.plugins.filter(
          p => p instanceof ForkTsCheckerWebpackPlugin,
        )[0];
    
        // remove the existing ForkTsCheckerWebpackPlugin
        // so that we can replace it with our modified version
        config.plugins = config.plugins.filter(
          p => !(p instanceof ForkTsCheckerWebpackPlugin),
        );
    
        // copy the options from the original ForkTsCheckerWebpackPlugin
        // instance and add the memoryLimit property
        const forkTsCheckerOptions = existingForkTsChecker.options;
        forkTsCheckerOptions.memoryLimit = 8192;
    
        config.plugins.push(new ForkTsCheckerWebpackPlugin(forkTsCheckerOptions));
      },
    };
    

    Now when I run my build, I see this in my output:

    -  Building for production...
    Starting type checking service...
    Using 1 worker with 8192MB memory limit
    

    More info on the configureWebpack option here: https://cli.vuejs.org/config/#configurewebpack

    To see the default Webpack configuration used by the Vue CLI, you can inspect it by running vue inspect: https://cli.vuejs.org/guide/webpack.html#inspecting-the-project-s-webpack-config

提交回复
热议问题