feat: auto fallback to legacy build for node@6 support

This commit is contained in:
Pooya Parsa 2018-06-01 16:56:13 +04:30
parent 35ee689473
commit 412ffd4c06
3 changed files with 14 additions and 11 deletions

View File

@ -1,8 +1,7 @@
#!/usr/bin/env node
const { join } = require('path')
const semver = require('semver')
const consola = require('consola')
const { name, engines } = require('../package.json')
// Global error handler
process.on('unhandledRejection', _error => {
@ -19,14 +18,6 @@ consola.add({
}
})
if (!semver.satisfies(process.version, engines.node)) {
consola.fatal(
`The engine "node" is incompatible with ${name}. Expected version "${
engines.node
}".`
)
}
const defaultCommand = 'dev'
const commands = new Set([defaultCommand, 'init', 'build', 'start', 'generate'])

View File

@ -7,9 +7,17 @@
const fs = require('fs')
const path = require('path')
const semver = require('semver')
if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
const { engines } = require('./package.json')
if (!semver.satisfies(process.version, engines.node)) {
// Auto fallback to legacy build on older node versions
module.exports = require('./dist/nuxt-legacy.js')
} else if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
// Use esm version when using linked repository to prevent builds
module.exports = require('./lib/index.js')
} else {
// Use production bundle by default
module.exports = require('./dist/nuxt.js')
}

View File

@ -1,7 +1,11 @@
import 'babel-polyfill'
import consola from 'consola'
import core from './core'
import builder from './builder'
import * as Utils from './common/utils'
consola.warn('You are using legacy build of Nuxt. Please consider upgrading your Node.js version to 8.x or later.')
export default Object.assign({ Utils }, core, builder)