mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
refactor: perf-loader and test
This commit is contained in:
parent
e2e124b8e4
commit
89bdd71591
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
1
test/fixtures/with-config/nuxt.config.js
vendored
1
test/fixtures/with-config/nuxt.config.js
vendored
@ -48,6 +48,7 @@ export default {
|
||||
publicPath: '/orion/',
|
||||
maxChunkSize: 300000,
|
||||
cssSourceMap: true,
|
||||
parallel: true,
|
||||
analyze: {
|
||||
analyzerMode: 'disabled',
|
||||
generateStatsFile: true,
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user