From 89bdd715916b9beaa3649c5189cab52afc64415d Mon Sep 17 00:00:00 2001 From: Clark Du Date: Mon, 2 Apr 2018 20:08:31 +0800 Subject: [PATCH] refactor: perf-loader and test --- lib/builder/builder.js | 2 +- lib/builder/webpack/utils/perf-loader.js | 11 +++++------ test/fixtures/with-config/nuxt.config.js | 1 + test/unit/wp.config.test.js | 11 +++++------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 2b8c8f7bd4..d7a11d75af 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -466,7 +466,7 @@ export default class Builder { // Warmup perfLoader before build if (this.options.build.parallel) { consola.start('Warming up worker pools') - this.perfLoader.warmup() + this.perfLoader.warmupAll() consola.success('Worker pools ready') } diff --git a/lib/builder/webpack/utils/perf-loader.js b/lib/builder/webpack/utils/perf-loader.js index 7ccff1ca8b..caac592419 100644 --- a/lib/builder/webpack/utils/perf-loader.js +++ b/lib/builder/webpack/utils/perf-loader.js @@ -1,6 +1,6 @@ import path from 'path' -import threadLoader from 'thread-loader' +import { warmup } from 'thread-loader' // https://github.com/webpack-contrib/thread-loader // https://github.com/webpack-contrib/cache-loader @@ -8,12 +8,11 @@ import threadLoader from 'thread-loader' export default class PerfLoader { constructor(options) { this.options = options - this.threadLoader = threadLoader + this.warmup = warmup this.workerPools = { js: { name: 'js', poolTimeout: this.options.dev ? Infinity : 2000 - }, css: { name: 'css', @@ -22,9 +21,9 @@ export default class PerfLoader { } } - warmup() { - this.threadLoader.warmup(this.workerPools.js, ['babel-loader', 'babel-preset-env']) - this.threadLoader.warmup(this.workerPools.css, ['css-loader']) + warmupAll() { + this.warmup(this.workerPools.js, ['babel-loader', 'babel-preset-env']) + this.warmup(this.workerPools.css, ['css-loader']) } pool(poolName, _loaders) { diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 4def85fcf8..81891cfb67 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -48,6 +48,7 @@ export default { publicPath: '/orion/', maxChunkSize: 300000, cssSourceMap: true, + parallel: true, analyze: { analyzerMode: 'disabled', generateStatsFile: true, diff --git a/test/unit/wp.config.test.js b/test/unit/wp.config.test.js index d99405aef5..8ec33ae001 100644 --- a/test/unit/wp.config.test.js +++ b/test/unit/wp.config.test.js @@ -15,12 +15,11 @@ describe('webpack configuration', () => { const css = { name: 'css', poolTimeout: Infinity } expect(perfLoader.workerPools).toMatchObject({ js, css }) - const warmup = jest.fn() - perfLoader.threadLoader = { warmup } - perfLoader.warmup() - expect(warmup).toHaveBeenCalledTimes(2) - expect(warmup).toHaveBeenCalledWith(js, ['babel-loader', 'babel-preset-env']) - expect(warmup).toHaveBeenCalledWith(css, ['css-loader']) + perfLoader.warmup = jest.fn() + perfLoader.warmupAll() + expect(perfLoader.warmup).toHaveBeenCalledTimes(2) + expect(perfLoader.warmup).toHaveBeenCalledWith(js, ['babel-loader', 'babel-preset-env']) + expect(perfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader']) const loaders = perfLoader.pool('js', { loader: 'test-perf-loader' }) const cacheDirectory = path.resolve('node_modules/.cache/cache-loader')