INFO Starting
Starting type
Using 1 worker with 2048MB memory limit
问题: 运行vue项目,使用2G内存,不知道如何更改。
DevOps 要求将前端生成限制为 1GB 的 RAM,防止 Jenkins 实例被关闭。使用标准Vue Cli创建项目,带 TypeScript。但是,TS 类型检查服务会忽略限制其内存使用的所有尝试,这始终为 2048 MB。@vue/cli
禁用它, 但这引入了其他问题。fork-ts-checker-webpack-plugin
$ NODE_OPTIONS=--max_old_space_size=1024 NODE_ENV=production node --max_old_space_size=1024 --max-old-space-size=1024 node_modules/.bin/vue-cli-service build
类型检查不生效,始终是2048 MB 。
ForkTsCheckerWebpackPlugin`fig
// fig.js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
ports = {configureWebpack: config => {
// get a reference to the existing ForkTsCheckerWebpackPluginconst existingForkTsChecker = config.plugins.filter(p => p instanceof ForkTsCheckerWebpackPlugin,)[0];
// remove the existing ForkTsCheckerWebpackPlugin// so that we can replace it with our modified versionconfig.plugins = config.plugins.filter(p => !(p instanceof ForkTsCheckerWebpackPlugin),);
// copy the options from the original ForkTsCheckerWebpackPlugin// instance and add the memoryLimit propertyconst forkTsCheckerOptions = existingForkTsChecker.Limit = 4096;
config.plugins.push(new ForkTsCheckerWebpackPlugin(forkTsCheckerOptions));},
};
info输出:Starting type
Using 1 worker with 4096MB memory limit
有关选项的信息, 请参阅此处:configurewebpack
若要查看 Vue CLI 使用的默认 Webpack 配置,vue webpack config
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const os=require('os');
ports = {//......,chainWebpack: config => {config.plugin('fork-ts-checker').tap(args => {let totalmem=Math.almem()/1024/1024); //get OS mem sizelet allowUseMem= totalmem>2500? 2048:1000;// in vue-cli shuld args[0]['typescript'].memoryLimitargs[0].memoryLimit = allowUseMem;return args})},//......
}
在node_modules/fork-ts-checker-webpack-plugin/lib/index.js
declare class ForkTsCheckerWebpackPlugin {static readonly DEFAULT_MEMORY_LIMIT = 4096;static readonly ONE_CPU = 1;static readonly ALL_CPUS: number;static readonly ONE_CPU_FREE: number;static readonly TWO_CPUS_FREE: number;readonly options: Partial<Options>;
参考链接
本文发布于:2024-01-28 04:02:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063857964635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |