mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +00:00
nuxt-generate
This commit is contained in:
parent
b9680bc3ea
commit
a8776de913
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,3 +7,6 @@ npm-debug.log
|
|||||||
|
|
||||||
# other
|
# other
|
||||||
.nuxt
|
.nuxt
|
||||||
|
|
||||||
|
# dist example generation
|
||||||
|
examples/**/dist
|
||||||
|
@ -5,7 +5,7 @@ const co = require('co')
|
|||||||
const pify = require('pify')
|
const pify = require('pify')
|
||||||
const debug = require('debug')('nuxt:generate')
|
const debug = require('debug')('nuxt:generate')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const { resolve, join } = require('path')
|
const { resolve, join, dirname } = require('path')
|
||||||
const copy = pify(fs.copy)
|
const copy = pify(fs.copy)
|
||||||
const remove = pify(fs.remove)
|
const remove = pify(fs.remove)
|
||||||
const writeFile = pify(fs.writeFile)
|
const writeFile = pify(fs.writeFile)
|
||||||
@ -24,7 +24,7 @@ module.exports = function () {
|
|||||||
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
|
var srcBuiltPath = resolve(this.dir, '.nuxt', 'dist')
|
||||||
var distPath = resolve(this.dir, this.options.generate.dir)
|
var distPath = resolve(this.dir, this.options.generate.dir)
|
||||||
var distNuxtPath = resolve(distPath, '_nuxt')
|
var distNuxtPath = resolve(distPath, '_nuxt')
|
||||||
co(function * () {
|
return co(function * () {
|
||||||
/*
|
/*
|
||||||
** Clean destination folder
|
** Clean destination folder
|
||||||
*/
|
*/
|
||||||
@ -46,16 +46,16 @@ module.exports = function () {
|
|||||||
** Generate html files from routes
|
** Generate html files from routes
|
||||||
*/
|
*/
|
||||||
var promises = []
|
var promises = []
|
||||||
this.options.routes.forEach((route) => {
|
this.routes.forEach((route) => {
|
||||||
var promise = this.renderRoute(route.path)
|
var promise = this.renderRoute(route.path)
|
||||||
.then(({ html }) => {
|
.then(({ html }) => {
|
||||||
var path = route.path
|
var path = join(route.path, '/', 'index.html') // /about -> /about/index.html
|
||||||
path += path[path.length - 1] === '/' ? 'index.html' : '.html'
|
|
||||||
debug('Generate file: ' + path)
|
debug('Generate file: ' + path)
|
||||||
path = join(distPath, path)
|
path = join(distPath, path)
|
||||||
|
// Make sure the sub folders are created
|
||||||
|
fs.mkdirsSync(dirname(path))
|
||||||
return writeFile(path, html, 'utf8')
|
return writeFile(path, html, 'utf8')
|
||||||
})
|
})
|
||||||
console.log(promise)
|
|
||||||
promises.push(promise)
|
promises.push(promise)
|
||||||
})
|
})
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nuxt",
|
"name": "nuxt",
|
||||||
"version": "0.3.1",
|
"version": "0.3.2",
|
||||||
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
|
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
Loading…
Reference in New Issue
Block a user