mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
Merge branch 'dev' of github.com:nuxt/nuxt.js into dev
This commit is contained in:
commit
b4b740f2a0
@ -1,5 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
|
- "8.0"
|
||||||
- "7.2"
|
- "7.2"
|
||||||
- "6.9"
|
- "6.9"
|
||||||
before_install:
|
before_install:
|
||||||
|
@ -52,8 +52,8 @@ if (analyzeBuild) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
||||||
new Nuxt(options).then(nuxt => {
|
var nuxt = module.exports = new Nuxt(options)
|
||||||
nuxt.build()
|
nuxt.build()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('[nuxt] Building done') // eslint-disable-line no-console
|
console.log('[nuxt] Building done') // eslint-disable-line no-console
|
||||||
})
|
})
|
||||||
@ -61,4 +61,3 @@ new Nuxt(options).then(nuxt => {
|
|||||||
console.error(err) // eslint-disable-line no-console
|
console.error(err) // eslint-disable-line no-console
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
19
bin/nuxt-dev
19
bin/nuxt-dev
@ -39,19 +39,20 @@ if (typeof options.rootDir !== 'string') {
|
|||||||
}
|
}
|
||||||
options.dev = true // Add hot reloading and watching changes
|
options.dev = true // Add hot reloading and watching changes
|
||||||
|
|
||||||
new Nuxt(options).then(nuxt => {
|
var nuxt = module.exports = new Nuxt(options)
|
||||||
var server = new nuxt.Server(nuxt)
|
var port = process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||||
.listen(process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host)
|
var host = process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||||
listenOnConfigChanges(nuxt, server)
|
var server = nuxt.server = new nuxt.Server(nuxt).listen(port, host)
|
||||||
|
|
||||||
nuxt.build()
|
listenOnConfigChanges(nuxt, server)
|
||||||
|
|
||||||
|
nuxt.build()
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err) // eslint-disable-line no-console
|
console.error(err) // eslint-disable-line no-console
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
function listenOnConfigChanges (nuxt, server) {
|
function listenOnConfigChanges(nuxt, server) {
|
||||||
// Listen on nuxt.config.js changes
|
// Listen on nuxt.config.js changes
|
||||||
var build = _.debounce(() => {
|
var build = _.debounce(() => {
|
||||||
debug('[nuxt.config.js] changed')
|
debug('[nuxt.config.js] changed')
|
||||||
@ -69,7 +70,7 @@ function listenOnConfigChanges (nuxt, server) {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
nuxt.renderer = null
|
nuxt.renderer = null
|
||||||
debug('Rebuilding the app...')
|
debug('Rebuilding the app...')
|
||||||
return (new Nuxt(options)).then(nuxt => nuxt.build())
|
return new Nuxt(options).build()
|
||||||
})
|
})
|
||||||
.then((nuxt) => {
|
.then((nuxt) => {
|
||||||
server.nuxt = nuxt
|
server.nuxt = nuxt
|
||||||
@ -80,6 +81,6 @@ function listenOnConfigChanges (nuxt, server) {
|
|||||||
})
|
})
|
||||||
}, 200)
|
}, 200)
|
||||||
var nuxtConfigFile = resolve(rootDir, nuxtConfigFileName)
|
var nuxtConfigFile = resolve(rootDir, nuxtConfigFileName)
|
||||||
chokidar.watch(nuxtConfigFile, Object.assign({}, nuxt.options.watchers.chokidar, { ignoreInitial: true }))
|
chokidar.watch(nuxtConfigFile, Object.assign({}, nuxt.options.watchers.chokidar, {ignoreInitial: true}))
|
||||||
.on('all', build)
|
.on('all', build)
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ if (typeof options.rootDir !== 'string') {
|
|||||||
options.dev = false // Force production mode (no webpack middleware called)
|
options.dev = false // Force production mode (no webpack middleware called)
|
||||||
|
|
||||||
console.log('[nuxt] Generating...') // eslint-disable-line no-console
|
console.log('[nuxt] Generating...') // eslint-disable-line no-console
|
||||||
new Nuxt(options).then(nuxt => {
|
var nuxt = module.exports = new Nuxt(options)
|
||||||
nuxt.generate()
|
nuxt.generate()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('[nuxt] Generate done') // eslint-disable-line no-console
|
console.log('[nuxt] Generate done') // eslint-disable-line no-console
|
||||||
})
|
})
|
||||||
@ -29,4 +29,3 @@ new Nuxt(options).then(nuxt => {
|
|||||||
console.error(err) // eslint-disable-line no-console
|
console.error(err) // eslint-disable-line no-console
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
@ -16,10 +16,7 @@ if (typeof options.rootDir !== 'string') {
|
|||||||
}
|
}
|
||||||
options.dev = false // Force production mode (no webpack middleware called)
|
options.dev = false // Force production mode (no webpack middleware called)
|
||||||
|
|
||||||
new Nuxt(options).then(nuxt => {
|
var nuxt = module.exports = new Nuxt(options)
|
||||||
new nuxt.Server(nuxt)
|
var port = process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||||
.listen(
|
var host = process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||||
process.env.PORT || process.env.npm_package_config_nuxt_port,
|
var server = nuxt.server = new nuxt.Server(nuxt).listen(port, host)
|
||||||
process.env.HOST || process.env.npm_package_config_nuxt_host
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
@ -14,7 +14,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
try { config = require(resolve(rootDir, 'nuxt.config.js')) } catch (e) {}
|
try { config = require(resolve(rootDir, 'nuxt.config.js')) } catch (e) {}
|
||||||
config.rootDir = rootDir // project folder
|
config.rootDir = rootDir // project folder
|
||||||
config.dev = false // production build
|
config.dev = false // production build
|
||||||
nuxt = await new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(4000, 'localhost')
|
server.listen(4000, 'localhost')
|
||||||
|
@ -97,8 +97,10 @@ export function options () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function build () {
|
export async function build () {
|
||||||
this._nuxtPages = typeof this.createRoutes !== 'function'
|
// Initialize modules first
|
||||||
|
await this.module.init()
|
||||||
// Check if pages dir exists and warn if not
|
// Check if pages dir exists and warn if not
|
||||||
|
this._nuxtPages = typeof this.createRoutes !== 'function'
|
||||||
if (this._nuxtPages) {
|
if (this._nuxtPages) {
|
||||||
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
if (!fs.existsSync(join(this.srcDir, 'pages'))) {
|
||||||
if (fs.existsSync(join(this.srcDir, '..', 'pages'))) {
|
if (fs.existsSync(join(this.srcDir, '..', 'pages'))) {
|
||||||
|
@ -4,13 +4,27 @@ import path from 'path'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import {uniq} from 'lodash'
|
import {uniq} from 'lodash'
|
||||||
import hash from 'hash-sum'
|
import hash from 'hash-sum'
|
||||||
import {chainFn} from './utils'
|
import {chainFn, sequence} from './utils'
|
||||||
|
|
||||||
|
const debug = require('debug')('nuxt:module')
|
||||||
|
|
||||||
class Module {
|
class Module {
|
||||||
constructor (nuxt) {
|
constructor (nuxt) {
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
this.options = nuxt.options
|
this.options = nuxt.options
|
||||||
this.modules = []
|
this.modules = []
|
||||||
|
this.initialized = false
|
||||||
|
}
|
||||||
|
|
||||||
|
async init () {
|
||||||
|
if (this.initialized) {
|
||||||
|
debug('[nuxt] Modules are already initialized')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Install all modules in sequence
|
||||||
|
await sequence(this.options.modules, this.addModule.bind(this))
|
||||||
|
// Indicate modules are already initialized
|
||||||
|
this.initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
addVendor (vendor) {
|
addVendor (vendor) {
|
||||||
@ -31,8 +45,7 @@ class Module {
|
|||||||
const srcPath = path.parse(src)
|
const srcPath = path.parse(src)
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!src || typeof src !== 'string' || !fs.existsSync(src)) {
|
if (!src || typeof src !== 'string' || !fs.existsSync(src)) {
|
||||||
// eslint-disable-next-line no-console
|
debug('[nuxt] invalid template', template)
|
||||||
console.warn('[nuxt] invalid template', template)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Generate unique and human readable dst filename
|
// Generate unique and human readable dst filename
|
||||||
@ -82,8 +95,15 @@ class Module {
|
|||||||
if (!moduleOpts) {
|
if (!moduleOpts) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Allow using babel style array options
|
||||||
|
if (Array.isArray(moduleOpts)) {
|
||||||
|
moduleOpts = {
|
||||||
|
src: moduleOpts[0],
|
||||||
|
options: moduleOpts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
// Allows passing runtime options to each module
|
// Allows passing runtime options to each module
|
||||||
const options = moduleOpts.options || {}
|
const options = moduleOpts.options || (typeof moduleOpts === 'object' ? moduleOpts : {})
|
||||||
const originalSrc = moduleOpts.src || moduleOpts
|
const originalSrc = moduleOpts.src || moduleOpts
|
||||||
// Resolve module
|
// Resolve module
|
||||||
let module = originalSrc
|
let module = originalSrc
|
||||||
|
@ -121,14 +121,6 @@ class Nuxt {
|
|||||||
this.utils = utils
|
this.utils = utils
|
||||||
// Add module integration
|
// Add module integration
|
||||||
this.module = new Module(this)
|
this.module = new Module(this)
|
||||||
// Install all modules in sequence and then return `this` instance
|
|
||||||
return utils.sequence(options.modules, this.module.addModule.bind(this.module))
|
|
||||||
.then(() => this)
|
|
||||||
.catch(/* istanbul ignore next */ (err) => {
|
|
||||||
console.error('[nuxt] error while initializing modules') // eslint-disable-line no-console
|
|
||||||
console.error(err) // eslint-disable-line no-console
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close (callback) {
|
close (callback) {
|
||||||
|
@ -14,7 +14,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
rootDir: resolve(__dirname, 'fixtures/basic'),
|
rootDir: resolve(__dirname, 'fixtures/basic'),
|
||||||
dev: true
|
dev: true
|
||||||
}
|
}
|
||||||
nuxt = await new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
|
@ -14,7 +14,7 @@ test('Fail with routes() which throw an error', async t => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const nuxt = await new Nuxt(options)
|
const nuxt = new Nuxt(options)
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
var oldExit = process.exit
|
var oldExit = process.exit
|
||||||
var oldCE = console.error // eslint-disable-line no-console
|
var oldCE = console.error // eslint-disable-line no-console
|
||||||
|
@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
||||||
config.rootDir = rootDir
|
config.rootDir = rootDir
|
||||||
config.dev = false
|
config.dev = false
|
||||||
nuxt = await new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
try {
|
try {
|
||||||
await nuxt.generate() // throw an error (of /validate route)
|
await nuxt.generate() // throw an error (of /validate route)
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
rootDir: resolve(__dirname, 'fixtures/basic'),
|
rootDir: resolve(__dirname, 'fixtures/basic'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = await new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
|
@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
rootDir: resolve(__dirname, 'fixtures/children'),
|
rootDir: resolve(__dirname, 'fixtures/children'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = await new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
|
@ -6,7 +6,7 @@ const readFile = pify(fs.readFile)
|
|||||||
|
|
||||||
test.before('Init Nuxt.js', async t => {
|
test.before('Init Nuxt.js', async t => {
|
||||||
const Nuxt = require('../')
|
const Nuxt = require('../')
|
||||||
const nuxt = await new Nuxt({
|
const nuxt = new Nuxt({
|
||||||
rootDir: resolve(__dirname, 'fixtures/dynamic-routes'),
|
rootDir: resolve(__dirname, 'fixtures/dynamic-routes'),
|
||||||
dev: false
|
dev: false
|
||||||
})
|
})
|
||||||
|
@ -13,7 +13,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
rootDir: resolve(__dirname, 'fixtures/error'),
|
rootDir: resolve(__dirname, 'fixtures/error'),
|
||||||
dev: false
|
dev: false
|
||||||
}
|
}
|
||||||
nuxt = await new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
|
9
test/fixtures/module/nuxt.config.js
vendored
9
test/fixtures/module/nuxt.config.js
vendored
@ -2,8 +2,13 @@ module.exports = {
|
|||||||
loading: true,
|
loading: true,
|
||||||
modules: [
|
modules: [
|
||||||
'~modules/basic',
|
'~modules/basic',
|
||||||
'~/modules/middleware',
|
{
|
||||||
'./modules/template'
|
src: '~/modules/middleware',
|
||||||
|
options: {
|
||||||
|
foo: 'bar'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
['./modules/template', {baz: 'ping'}]
|
||||||
],
|
],
|
||||||
serverMiddleware: [
|
serverMiddleware: [
|
||||||
'./modules/middleware/midd2'
|
'./modules/middleware/midd2'
|
||||||
|
@ -8,7 +8,7 @@ test('Nuxt.js Class', t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('Nuxt.js Instance', async t => {
|
test('Nuxt.js Instance', async t => {
|
||||||
const nuxt = await new Nuxt()
|
const nuxt = new Nuxt()
|
||||||
t.is(typeof nuxt, 'object')
|
t.is(typeof nuxt, 'object')
|
||||||
t.is(nuxt.dev, true)
|
t.is(nuxt.dev, true)
|
||||||
t.is(typeof nuxt.build, 'function')
|
t.is(typeof nuxt.build, 'function')
|
||||||
@ -16,7 +16,7 @@ test('Nuxt.js Instance', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.serial('Fail when build not done and try to render', async t => {
|
test.serial('Fail when build not done and try to render', async t => {
|
||||||
const nuxt = await new Nuxt({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname, 'fixtures/empty')
|
rootDir: resolve(__dirname, 'fixtures/empty')
|
||||||
})
|
})
|
||||||
@ -37,7 +37,7 @@ test.serial('Fail when build not done and try to render', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.serial('Fail to build when no pages/ directory but is in the parent', async t => {
|
test.serial('Fail to build when no pages/ directory but is in the parent', async t => {
|
||||||
const nuxt = await new Nuxt({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
|
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
|
||||||
})
|
})
|
||||||
@ -58,7 +58,7 @@ test.serial('Fail to build when no pages/ directory but is in the parent', async
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.serial('Fail to build when no pages/ directory', async t => {
|
test.serial('Fail to build when no pages/ directory', async t => {
|
||||||
const nuxt = await new Nuxt({
|
const nuxt = new Nuxt({
|
||||||
dev: false,
|
dev: false,
|
||||||
rootDir: resolve(__dirname)
|
rootDir: resolve(__dirname)
|
||||||
})
|
})
|
||||||
|
@ -8,6 +8,8 @@ const url = (route) => 'http://localhost:' + port + route
|
|||||||
let nuxt = null
|
let nuxt = null
|
||||||
let server = null
|
let server = null
|
||||||
|
|
||||||
|
const wp = p => /^win/.test(process.platform) ? p.replace(/[\\/]/g, '\\\\') : p
|
||||||
|
|
||||||
// Init nuxt.js and create server listening on localhost:4000
|
// Init nuxt.js and create server listening on localhost:4000
|
||||||
test.before('Init Nuxt.js', async t => {
|
test.before('Init Nuxt.js', async t => {
|
||||||
const Nuxt = require('../')
|
const Nuxt = require('../')
|
||||||
@ -15,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
||||||
config.rootDir = rootDir
|
config.rootDir = rootDir
|
||||||
config.dev = false
|
config.dev = false
|
||||||
nuxt = await new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
@ -26,7 +28,7 @@ test('Vendor', async t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('Plugin', async t => {
|
test('Plugin', async t => {
|
||||||
t.true(nuxt.options.plugins[0].src.includes('fixtures/module/.nuxt/basic.reverse.'), 'plugin added to config')
|
t.true(nuxt.options.plugins[0].src.includes(wp('fixtures/module/.nuxt/basic.reverse.')), 'plugin added to config')
|
||||||
const { html } = await nuxt.renderRoute('/')
|
const { html } = await nuxt.renderRoute('/')
|
||||||
t.true(html.includes('<h1>TXUN</h1>'), 'plugin works')
|
t.true(html.includes('<h1>TXUN</h1>'), 'plugin works')
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,7 @@ let utils
|
|||||||
// Init nuxt.js and create server listening on localhost:4000
|
// Init nuxt.js and create server listening on localhost:4000
|
||||||
test.before('Init Nuxt.js', async t => {
|
test.before('Init Nuxt.js', async t => {
|
||||||
const Nuxt = require('../')
|
const Nuxt = require('../')
|
||||||
let nuxt = await new Nuxt({ dev: false })
|
let nuxt = new Nuxt({ dev: false })
|
||||||
utils = nuxt.utils
|
utils = nuxt.utils
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
||||||
config.rootDir = rootDir
|
config.rootDir = rootDir
|
||||||
config.dev = false
|
config.dev = false
|
||||||
nuxt = await new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.build()
|
await nuxt.build()
|
||||||
server = new nuxt.Server(nuxt)
|
server = new nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
@ -110,5 +110,5 @@ test.after('Should be able to start Nuxt with build done', async t => {
|
|||||||
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
||||||
config.rootDir = rootDir
|
config.rootDir = rootDir
|
||||||
config.dev = false
|
config.dev = false
|
||||||
nuxt = await new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user