Skip to content

Commit

Permalink
feat: allow parallel option to be an integer (#3864)
Browse files Browse the repository at this point in the history
closes #3850
  • Loading branch information
sodatea committed Apr 27, 2019
1 parent e9259cd commit a351cba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/@vue/cli-plugin-babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function genTranspileDepRegex (transpileDependencies) {
}

module.exports = (api, options) => {
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
const useThreads = process.env.NODE_ENV === 'production' && !!options.parallel
const cliServicePath = require('path').dirname(require.resolve('@vue/cli-service'))
const transpileDepRegex = genTranspileDepRegex(options.transpileDependencies)

Expand Down Expand Up @@ -59,9 +59,13 @@ module.exports = (api, options) => {
.end()

if (useThreads) {
jsRule
const threadLoaderConfig = jsRule
.use('thread-loader')
.loader('thread-loader')

if (typeof options.parallel === 'number') {
threadLoaderConfig.options({ workers: options.parallel })
}
}

jsRule
Expand Down
8 changes: 6 additions & 2 deletions packages/@vue/cli-plugin-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')

module.exports = (api, options) => {
const fs = require('fs')
const useThreads = process.env.NODE_ENV === 'production' && options.parallel
const useThreads = process.env.NODE_ENV === 'production' && !!options.parallel

api.chainWebpack(config => {
config.resolveLoader.modules.prepend(path.join(__dirname, 'node_modules'))
Expand Down Expand Up @@ -37,7 +37,11 @@ module.exports = (api, options) => {

if (useThreads) {
addLoader({
loader: 'thread-loader'
loader: 'thread-loader',
options:
typeof options.parallel === 'number'
? { workers: options.parallel }
: {}
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const schema = createSchema(joi => joi.object({
runtimeCompiler: joi.boolean(),
transpileDependencies: joi.array(),
productionSourceMap: joi.boolean(),
parallel: joi.boolean(),
parallel: joi.alternatives().try([
joi.boolean(),
joi.number().integer()
]),
devServer: joi.object(),
pages: joi.object().pattern(
/\w+/,
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/types/ProjectOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ProjectOptions {
runtimeCompiler?: boolean;
transpileDependencies?: Array<string | RegExp>;
productionSourceMap?: boolean;
parallel?: boolean;
parallel?: boolean | number;
devServer?: object;
pages?: {
[key: string]: PageEntry | PageConfig;
Expand Down

0 comments on commit a351cba

Please sign in to comment.