mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
perf(build-fixtures): parallel builds
This commit is contained in:
parent
584b943688
commit
19775d58f7
@ -116,6 +116,7 @@
|
|||||||
"webpack-stylish": "^0.1.6"
|
"webpack-stylish": "^0.1.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@expo/spawn-async": "^1.3.0",
|
||||||
"babel-eslint": "^8.2.1",
|
"babel-eslint": "^8.2.1",
|
||||||
"codecov": "^3.0.0",
|
"codecov": "^3.0.0",
|
||||||
"eslint": "^4.18.2",
|
"eslint": "^4.18.2",
|
||||||
@ -134,6 +135,7 @@
|
|||||||
"jest": "^22.4.2",
|
"jest": "^22.4.2",
|
||||||
"jest-runner-eslint": "^0.4.0",
|
"jest-runner-eslint": "^0.4.0",
|
||||||
"jsdom": "^11.6.2",
|
"jsdom": "^11.6.2",
|
||||||
|
"p-limit": "^1.2.0",
|
||||||
"puppeteer": "^1.0.0",
|
"puppeteer": "^1.0.0",
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"request-promise-native": "^1.0.5",
|
"request-promise-native": "^1.0.5",
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.NODE_ENV = 'test'
|
process.env.NODE_ENV = 'test'
|
||||||
|
|
||||||
const { Builder, Nuxt } = require('..')
|
const { resolve } = require('path')
|
||||||
const { requireModule } = require('../lib/common/module')
|
const { cpus } = require('os')
|
||||||
const path = require('path')
|
|
||||||
const fs = require('fs')
|
const spawnAsync = require('@expo/spawn-async')
|
||||||
const ORA = require('ora')
|
const ORA = require('ora')
|
||||||
|
const pLimit = require('p-limit')
|
||||||
|
|
||||||
const fixtures = [
|
const fixtures = [
|
||||||
// csr, dev, generate, fail generate, fallback generate, ssr, ssr csp, spa
|
|
||||||
'basic',
|
|
||||||
|
|
||||||
'children',
|
'children',
|
||||||
'custom-dirs',
|
'custom-dirs',
|
||||||
'debug',
|
'debug',
|
||||||
@ -20,37 +18,52 @@ const fixtures = [
|
|||||||
'error',
|
'error',
|
||||||
'module',
|
'module',
|
||||||
'ssr',
|
'ssr',
|
||||||
'with-config'
|
'with-config',
|
||||||
|
|
||||||
|
// csr,
|
||||||
|
// dev,
|
||||||
|
// generate,
|
||||||
|
// fail generate,
|
||||||
|
// fallback generate,
|
||||||
|
// ssr,
|
||||||
|
// ssr csp,
|
||||||
|
// spa
|
||||||
|
'basic'
|
||||||
]
|
]
|
||||||
|
|
||||||
const spinner = new ORA()
|
const spinner = new ORA()
|
||||||
|
const nuxtBuild = resolve(__dirname, '../bin/nuxt-build')
|
||||||
|
|
||||||
|
let _total = fixtures.length
|
||||||
|
let _done = 0
|
||||||
|
let remaining = () => ` (${_done}/${_total})`
|
||||||
|
|
||||||
async function buildFixture(name) {
|
async function buildFixture(name) {
|
||||||
spinner.info('Loading config for fixture ' + name)
|
_done++
|
||||||
|
|
||||||
const rootDir = path.resolve(__dirname, '../test/fixtures', name)
|
let _name = `'${name}'`
|
||||||
const configFile = path.resolve(rootDir, 'nuxt.config.js')
|
|
||||||
const config = fs.existsSync(configFile) ? requireModule(configFile) : {}
|
|
||||||
|
|
||||||
config.rootDir = rootDir
|
spinner.info('Building ' + _name + remaining())
|
||||||
config.dev = false
|
|
||||||
|
|
||||||
spinner.start('Building fixture ' + name)
|
const rootDir = resolve(__dirname, '../test/fixtures', name)
|
||||||
|
|
||||||
const nuxt = new Nuxt(config)
|
await spawnAsync('node', [nuxtBuild, rootDir])
|
||||||
const builder = new Builder(nuxt)
|
.catch((err) => {
|
||||||
|
spinner.warn('Errors while building ' + _name + ': ' + err)
|
||||||
await builder.build()
|
})
|
||||||
|
.then(() => {
|
||||||
spinner.succeed('Built fixture ' + name)
|
spinner.succeed('Built fixture: ' + _name + remaining())
|
||||||
|
})
|
||||||
await nuxt.close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
for (let fixture of fixtures) {
|
const cpuCount = cpus().length
|
||||||
await buildFixture(fixture)
|
|
||||||
}
|
spinner.info('Builing with concurrency of ' + cpuCount)
|
||||||
|
const limit = pLimit(cpuCount)
|
||||||
|
|
||||||
|
await Promise.all(fixtures.map(fixture =>
|
||||||
|
limit(() => buildFixture(fixture))))
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
@ -85,6 +85,12 @@
|
|||||||
lodash "^4.2.0"
|
lodash "^4.2.0"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
|
"@expo/spawn-async@^1.3.0":
|
||||||
|
version "1.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@expo/spawn-async/-/spawn-async-1.3.0.tgz#01b8a4f6bba10b792663f9272df66c7e90166dad"
|
||||||
|
dependencies:
|
||||||
|
cross-spawn "^5.1.0"
|
||||||
|
|
||||||
"@nuxtjs/friendly-errors-webpack-plugin@^2.0.0":
|
"@nuxtjs/friendly-errors-webpack-plugin@^2.0.0":
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@nuxtjs/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-2.0.0.tgz#70fb321c78362e2b4bce1d522ecdf7f87a4dacec"
|
resolved "https://registry.yarnpkg.com/@nuxtjs/friendly-errors-webpack-plugin/-/friendly-errors-webpack-plugin-2.0.0.tgz#70fb321c78362e2b4bce1d522ecdf7f87a4dacec"
|
||||||
@ -4997,7 +5003,7 @@ p-finally@^1.0.0:
|
|||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
|
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
|
||||||
|
|
||||||
p-limit@^1.1.0:
|
p-limit@^1.1.0, p-limit@^1.2.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
|
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user