[Vue CLI 3] 配置解析之 parallel

官方文檔中介紹過在 vue.config.js 文件中能夠配置 parallel,做用以下:vue

是否爲 Babel 或 TypeScript 使用 thread-loader。
該選項在系統的 CPU 有多於一個內核時自動啓用,僅做用於生產構建

咱們看一下源碼部分:node

parallel 接受 boolean 值:webpack

parallel: joi.boolean()

默認設置以下:git

parallel: hasMultipleCores()

依賴了函數 hasMultipleCoresgithub

in some cases cpus() returns undefined, and may simply throw in the future

詳情見:https://github.com/nodejs/nod...web

經過核心包 oscpus 函數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

而後若是 useThreadstrue,會 use 插件 thread-loader

if (useThreads) {
  jsRule
    .use('thread-loader')
      .loader('thread-loader')
}

因此你們應該知道,若是你在某個項目裏面看到 vue.config.js 配置了:

parallel: require('os').cpus().length > 1

實際上是多餘的,並且不保險

相關文章
相關標籤/搜索