Skip to content

Commit

Permalink
fix: avoid os.cpus() error in certain envs
Browse files Browse the repository at this point in the history
close #2110
  • Loading branch information
yyx990803 committed Aug 8, 2018
1 parent 70160cc commit 327d041
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ exports.validate = (options, cb) => {
validate(options, schema, cb)
}

// #2110
// https://github.com/nodejs/node/issues/19022
// in some cases cpus() returns undefined, and may simply throw in the future
function hasMultipleCores () {
try {
return require('os').cpus().length > 1
} catch (e) {
return false
}
}

exports.defaults = () => ({
// project deployment base
baseUrl: '/',
Expand Down Expand Up @@ -74,7 +85,7 @@ exports.defaults = () => ({

// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
parallel: require('os').cpus().length > 1,
parallel: hasMultipleCores(),

// multi-page config
pages: undefined,
Expand Down

0 comments on commit 327d041

Please sign in to comment.