mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
relative import url
This commit is contained in:
parent
9e433764d7
commit
b14cc1951a
@ -6,7 +6,7 @@
|
||||
<script>
|
||||
import Vue from 'vue'
|
||||
import NuxtChild from './nuxt-child'
|
||||
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./nuxt-error.vue" %>'
|
||||
import NuxtError from '<%= components.ErrorPage ? "../" + components.ErrorPage : "./nuxt-error.vue" %>'
|
||||
|
||||
export default {
|
||||
name: 'nuxt',
|
||||
|
22
lib/build.js
22
lib/build.js
@ -9,7 +9,7 @@ import webpack from 'webpack'
|
||||
import PostCompilePlugin from 'post-compile-webpack-plugin'
|
||||
import serialize from 'serialize-javascript'
|
||||
import { createBundleRenderer } from 'vue-server-renderer'
|
||||
import { join, resolve, basename, dirname } from 'path'
|
||||
import { join, resolve, basename, dirname, relative } from 'path'
|
||||
import { isUrl, r, wp } from './utils'
|
||||
import clientWebpackConfig from './webpack/client.config.js'
|
||||
import serverWebpackConfig from './webpack/server.config.js'
|
||||
@ -138,7 +138,7 @@ async function buildFiles () {
|
||||
}
|
||||
|
||||
function addAppTemplate () {
|
||||
let templatePath = resolve(this.buildDir, 'dist', 'index.html')
|
||||
let templatePath = relative(this.buildDir, 'dist', 'index.html')
|
||||
if (fs.existsSync(templatePath)) {
|
||||
this.appTemplate = _.template(fs.readFileSync(templatePath, 'utf8'), {
|
||||
interpolate: /{{([\s\S]+?)}}/g
|
||||
@ -163,6 +163,8 @@ async function generateRoutesAndFiles () {
|
||||
'components/nuxt-link.js',
|
||||
'components/nuxt.vue'
|
||||
]
|
||||
|
||||
const srcImportDir = relative(this.buildDir, this.srcDir)
|
||||
const templateVars = {
|
||||
options: this.options,
|
||||
uniqBy: _.uniqBy,
|
||||
@ -190,7 +192,7 @@ async function generateRoutesAndFiles () {
|
||||
loading: (typeof this.options.loading === 'string' ? r(this.srcDir, this.options.loading) : this.options.loading),
|
||||
transition: this.options.transition,
|
||||
components: {
|
||||
ErrorPage: this.options.ErrorPage ? r(this.options.ErrorPage) : null
|
||||
ErrorPage: this.options.ErrorPage ? join(srcImportDir, this.options.ErrorPage) : null
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,17 +202,17 @@ async function generateRoutesAndFiles () {
|
||||
layoutsFiles.forEach((file) => {
|
||||
let name = file.split('/').slice(-1)[0].replace('.vue', '')
|
||||
if (name === 'error') return
|
||||
templateVars.layouts[name] = r(this.srcDir, file)
|
||||
templateVars.layouts[name] = join(srcImportDir, file)
|
||||
})
|
||||
if (layoutsFiles.includes('layouts/error.vue')) {
|
||||
templateVars.components.ErrorPage = r(this.srcDir, 'layouts/error.vue')
|
||||
templateVars.components.ErrorPage = join(srcImportDir, 'layouts/error.vue')
|
||||
}
|
||||
}
|
||||
// If no default layout, create its folder and add the default folder
|
||||
if (!templateVars.layouts.default) {
|
||||
await mkdirp(r(this.buildDir, 'layouts'))
|
||||
templatesFiles.push('layouts/default.vue')
|
||||
templateVars.layouts.default = r(__dirname, 'app', 'layouts', 'default.vue')
|
||||
templateVars.layouts.default = join(relative(this.buildDir, __dirname), 'app', 'layouts', 'default.vue')
|
||||
}
|
||||
|
||||
// -- Routes --
|
||||
@ -219,9 +221,9 @@ async function generateRoutesAndFiles () {
|
||||
if (this._nuxtPages) {
|
||||
// Use nuxt.js createRoutes bases on pages/
|
||||
const files = await glob('pages/**/*.vue', {cwd: this.srcDir})
|
||||
templateVars.router.routes = createRoutes(files, this.srcDir)
|
||||
templateVars.router.routes = createRoutes(files, srcImportDir)
|
||||
} else {
|
||||
templateVars.router.routes = this.createRoutes(this.srcDir)
|
||||
templateVars.router.routes = this.createRoutes(srcImportDir)
|
||||
}
|
||||
// router.extendRoutes method
|
||||
if (typeof this.options.router.extendRoutes === 'function') {
|
||||
@ -295,11 +297,11 @@ async function generateRoutesAndFiles () {
|
||||
}))
|
||||
}
|
||||
|
||||
function createRoutes (files, srcDir) {
|
||||
function createRoutes (files, importDir) {
|
||||
let routes = []
|
||||
files.forEach((file) => {
|
||||
let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1)
|
||||
let route = { name: '', path: '', component: r(srcDir, file) }
|
||||
let route = { name: '', path: '', component: join(importDir, file) }
|
||||
let parent = routes
|
||||
keys.forEach((key, i) => {
|
||||
route.name = route.name ? route.name + '-' + key.replace('_', '') : key.replace('_', '')
|
||||
|
Loading…
Reference in New Issue
Block a user