Use relative path

This commit is contained in:
Sebastien Chopin 2017-06-20 19:12:06 +02:00
parent 365d51c0b7
commit e1126d799c
3 changed files with 18 additions and 10 deletions

View File

@ -6,7 +6,7 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import NuxtChild from './nuxt-child' import NuxtChild from './nuxt-child'
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./nuxt-error.vue" %>' import NuxtError from '<%= components.ErrorPage ? (components.ErrorPage.includes('~') ? components.ErrorPage : "../" + components.ErrorPage) : "./nuxt-error.vue" %>'
export default { export default {
name: 'nuxt', name: 'nuxt',

View File

@ -23,7 +23,7 @@ function recursiveRoutes(routes, tab, components) {
var _components = [] var _components = []
var _routes = recursiveRoutes(router.routes, '\t\t', _components) var _routes = recursiveRoutes(router.routes, '\t\t', _components)
uniqBy(_components, '_name').forEach((route) => { %> uniqBy(_components, '_name').forEach((route) => { %>
const <%= route._name %> = () => import('<%= route.component %>' /* webpackChunkName: "pages/<%= route.name %>" */) const <%= route._name %> = () => import('<%= relative(route.component) %>' /* webpackChunkName: "pages/<%= route.name %>" */)
<% }) %> <% }) %>
<% if (router.scrollBehavior) { %> <% if (router.scrollBehavior) { %>

View File

@ -5,7 +5,7 @@ import hash from 'hash-sum'
import pify from 'pify' import pify from 'pify'
import webpack from 'webpack' import webpack from 'webpack'
import serialize from 'serialize-javascript' import serialize from 'serialize-javascript'
import { join, resolve, basename, dirname } from 'path' import { join, resolve, basename, dirname, relative } from 'path'
import Tapable from 'tappable' import Tapable from 'tappable'
import MFS from 'memory-fs' import MFS from 'memory-fs'
import webpackDevMiddleware from 'webpack-dev-middleware' import webpackDevMiddleware from 'webpack-dev-middleware'
@ -134,10 +134,10 @@ export default class Builder extends Tapable {
}), }),
appPath: './App.vue', appPath: './App.vue',
layouts: Object.assign({}, this.options.layouts), layouts: Object.assign({}, this.options.layouts),
loading: typeof this.options.loading === 'string' ? r(this.options.srcDir, this.options.loading) : this.options.loading, loading: typeof this.options.loading === 'string' ? this.relative(r(this.options.srcDir, this.options.loading)) : this.options.loading,
transition: this.options.transition, transition: this.options.transition,
components: { components: {
ErrorPage: this.options.ErrorPage ? r(this.options.ErrorPage) : null ErrorPage: this.options.ErrorPage ? this.relative(r(this.options.ErrorPage)) : null
} }
} }
@ -147,17 +147,17 @@ export default class Builder extends Tapable {
layoutsFiles.forEach((file) => { layoutsFiles.forEach((file) => {
let name = file.split('/').slice(-1)[0].replace('.vue', '') let name = file.split('/').slice(-1)[0].replace('.vue', '')
if (name === 'error') return if (name === 'error') return
templateVars.layouts[name] = r(this.options.srcDir, file) templateVars.layouts[name] = this.relative(r(this.options.srcDir, file))
}) })
if (layoutsFiles.includes('layouts/error.vue')) { if (layoutsFiles.includes('layouts/error.vue') && !templateVars.components.ErrorPage) {
templateVars.components.ErrorPage = r(this.options.srcDir, 'layouts/error.vue') templateVars.components.ErrorPage = this.relative(r(this.options.srcDir, 'layouts/error.vue'))
} }
} }
// If no default layout, create its folder and add the default folder // If no default layout, create its folder and add the default folder
if (!templateVars.layouts.default) { if (!templateVars.layouts.default) {
await mkdirp(r(this.options.buildDir, 'layouts')) await mkdirp(r(this.options.buildDir, 'layouts'))
templatesFiles.push('layouts/default.vue') templatesFiles.push('layouts/default.vue')
templateVars.layouts.default = r(this.options.nuxtAppDir, 'layouts', 'default.vue') templateVars.layouts.default = './layouts/default.vue'
} }
// -- Routes -- // -- Routes --
@ -224,7 +224,8 @@ export default class Builder extends Tapable {
serialize, serialize,
hash, hash,
r, r,
wp wp,
relative: this.relative.bind(this)
} }
}) })
const content = template(Object.assign({}, templateVars, { const content = template(Object.assign({}, templateVars, {
@ -407,6 +408,13 @@ export default class Builder extends Tapable {
customFilesWatcher.close() customFilesWatcher.close()
}) })
} }
relative(dest) {
if (dest && dest.includes('~')) {
return dest
}
return relative(this.options.buildDir, dest)
}
} }
const STATUS = { const STATUS = {