官方文档中介绍过在 vue.config.js
文件中能够配置 parallel
,做用以下:vue
是否为 Babel 或 TypeScript 使用 thread-loader。 该选项在系统的 CPU 有多于一个内核时自动启用,仅做用于生产构建
咱们看一下源码
部分:node
parallel
接受 boolean
值:webpack
parallel: joi.boolean()
默认设置以下:git
parallel: hasMultipleCores()
依赖了函数 hasMultipleCores
github
in some cases cpus() returns undefined, and may simply throw in the future
详情见:https://github.com/nodejs/nod...web
经过核心包 os
的 cpus
函数babel
function hasMultipleCores () { try { return require('os').cpus().length > 1 } catch (e) { return false } }
那它会影响什么呢?函数
babel 部分ui
在 @vue/cli-plugin-babel/README.md 也提到了:插件
thread-loader is enabled by default when the machine has more than 1 CPU cores. This can be turned off by setting parallel: false
in vue.config.js
.
咱们来看一下源码:
在线上环境和 vue.config.js
中的配置 parallel
:
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
而后若是 useThreads
为 true
,会 use
插件 thread-loader
if (useThreads) { jsRule .use('thread-loader') .loader('thread-loader') }
因此你们应该知道,若是你在某个项目里面看到 vue.config.js 配置了:
parallel: require('os').cpus().length > 1
实际上是多余
的,并且不保险