mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
generate ok
This commit is contained in:
parent
da9c311b54
commit
2c4a512dda
@ -1,5 +1,14 @@
|
||||
module.exports = {
|
||||
build: {
|
||||
vendor: ['axios']
|
||||
},
|
||||
generate: {
|
||||
routeParams: {
|
||||
'/users/:id': [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}],
|
||||
'/posts/:slug': [{slug: 'welcome'}, {slug: 'foo'}, {slug: 'bar'}],
|
||||
'/posts/:slug/comments': [{slug: 'welcome'}, {slug: 'foo'}, {slug: 'bar'}],
|
||||
'/posts/:slug/:name': [{slug: 'welcome', name: 'a'}, {slug: 'foo', name: 'b'}, {slug: 'bar', name: 'a'}],
|
||||
'/projects/:slug': [{slug: 'toto'}, {slug: 'titi'}, {slug: 'tutu'}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ function * generateRoutesAndFiles () {
|
||||
*/
|
||||
const files = yield glob('pages/**/*.vue', { cwd: this.srcDir })
|
||||
this.routes = _.uniq(_.map(files, (file) => {
|
||||
return file.replace(/^pages/, '').replace(/\.vue$/, '').replace('/index', '').replace('_', ':').replace('', '/').replace(/\/{2,}/g, '/')
|
||||
return file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/index/g, '').replace(/_/g, ':').replace('', '/').replace(/\/{2,}/g, '/')
|
||||
}))
|
||||
/*
|
||||
** Interpret and move template files to .nuxt/
|
||||
|
@ -69,15 +69,15 @@ module.exports = function () {
|
||||
*/
|
||||
let routes = []
|
||||
this.routes.forEach((route) => {
|
||||
if (route.path.includes(':') || route.path.includes('*')) {
|
||||
const routeParams = this.options.generate.routeParams[route.path]
|
||||
if (route.includes(':') || route.includes('*')) {
|
||||
const routeParams = this.options.generate.routeParams[route]
|
||||
if (!routeParams) {
|
||||
console.error(`Could not generate the dynamic route ${route.path}, please add the mapping params in nuxt.config.js (generate.routeParams).`) // eslint-disable-line no-console
|
||||
console.error(`Could not generate the dynamic route ${route}, please add the mapping params in nuxt.config.js (generate.routeParams).`) // eslint-disable-line no-console
|
||||
return process.exit(1)
|
||||
}
|
||||
const toPath = pathToRegexp.compile(route.path)
|
||||
const toPath = pathToRegexp.compile(route)
|
||||
routes = routes.concat(routeParams.map((params) => {
|
||||
return Object.assign({}, route, { path: toPath(params) })
|
||||
return toPath(params)
|
||||
}))
|
||||
} else {
|
||||
routes.push(route)
|
||||
@ -87,8 +87,8 @@ module.exports = function () {
|
||||
while (routes.length) {
|
||||
yield routes.splice(0, 500).map((route) => {
|
||||
return co(function * () {
|
||||
const { html } = yield self.renderRoute(route.path)
|
||||
var path = join(route.path, sep, 'index.html') // /about -> /about/index.html
|
||||
const { html } = yield self.renderRoute(route)
|
||||
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
||||
debug('Generate file: ' + path)
|
||||
path = join(distPath, path)
|
||||
// Make sure the sub folders are created
|
||||
|
Loading…
Reference in New Issue
Block a user