minor fixes

This commit is contained in:
Pooya Parsa 2018-01-11 23:13:34 +03:30
parent 0cb0beb1c5
commit 3c4b57e1f7
4 changed files with 28 additions and 21 deletions

View File

@ -80,8 +80,7 @@ if (options.mode !== 'spa') {
.build()
.then(() => debug('Building done'))
.catch(err => {
console.error(err)
process.exit(1)
Utils.fatalError(err)
})
} else {
const s = Date.now()

View File

@ -60,7 +60,7 @@ module.exports = class Builder {
if (typeof p === 'string') p = { src: p }
const pluginBaseName = basename(p.src, extname(p.src)).replace(/[^a-zA-Z?\d\s:]/g, '')
return {
src: this.nuxt.resolvePath(p.src),
src: this.nuxt.resolveAlias(p.src),
ssr: (p.ssr !== false),
name: 'nuxt_plugin_' + pluginBaseName + '_' + hash(p.src)
}
@ -333,7 +333,7 @@ module.exports = class Builder {
// -- Loading indicator --
if (this.options.loadingIndicator.name) {
const indicatorPath1 = resolve(this.options.nuxtAppDir, 'views/loading', this.options.loadingIndicator.name + '.html')
const indicatorPath2 = this.nuxt.resolvePath(this.options.loadingIndicator.name)
const indicatorPath2 = this.nuxt.resolveAlias(this.options.loadingIndicator.name)
const indicatorPath = existsSync(indicatorPath1) ? indicatorPath1 : (existsSync(indicatorPath2) ? indicatorPath2 : null)
if (indicatorPath) {
templatesFiles.push({
@ -365,6 +365,7 @@ module.exports = class Builder {
wp,
wChunk,
resolvePath: this.nuxt.resolvePath.bind(this.nuxt),
resolveAlias: this.nuxt.resolveAlias.bind(this.nuxt),
relativeToBuild: this.relativeToBuild
}
})

View File

@ -48,9 +48,7 @@ module.exports = class ModuleContainer {
// Generate unique and human readable dst filename
const dst =
template.fileName ||
`${path.basename(srcPath.dir)}.${srcPath.name}.${hash(src)}.${
srcPath.ext
}`
path.basename(srcPath.dir) + `.${srcPath.name}.${hash(src)}` + srcPath.ext
// Add to templates list
const templateObj = {
@ -113,11 +111,7 @@ module.exports = class ModuleContainer {
// Resolve handler
if (!handler) {
try {
handler = require(this.nuxt.resolvePath(src))
} catch (err) {
this.nuxt.onError(err, src)
}
}
// Validate handler

View File

@ -6,7 +6,7 @@ const chalk = require('chalk')
const { existsSync } = require('fs-extra')
const { Options } = require('../common')
const { sequence, printError, printWarn } = require('../common/utils')
const { resolve } = require('path')
const { resolve, join } = require('path')
const { version } = require('../../package.json')
const ModuleContainer = require('./module')
const Renderer = require('./renderer')
@ -180,6 +180,18 @@ module.exports = class Nuxt {
})
}
resolveAlias(path) {
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
return join(this.options.rootDir, path.substr(2))
}
if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
return join(this.options.srcDir, path.substr(1))
}
return resolve(this.options.srcDir, path)
}
resolvePath(path) {
// Try to resolve using NPM resolve path first
try {
@ -195,18 +207,19 @@ module.exports = class Nuxt {
}
}
let _path = path
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
_path = resolve(this.options.rootDir, path.substr(2))
} else if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
_path = resolve(this.options.srcDir, path.substr(1))
let _path = this.resolveAlias(path)
if (existsSync(_path)) {
return _path
}
for (let ext of [''].concat(this.options.extensions)) {
if (existsSync(_path + ext)) {
return _path + ext
for (let ext of this.options.extensions) {
if (existsSync(_path + '.' + ext)) {
return _path + '.' + ext
}
}
throw new Error(`Cannot resolve "${path}" from "${_path}"`)
}
async close(callback) {