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() .build()
.then(() => debug('Building done')) .then(() => debug('Building done'))
.catch(err => { .catch(err => {
console.error(err) Utils.fatalError(err)
process.exit(1)
}) })
} else { } else {
const s = Date.now() const s = Date.now()

View File

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

View File

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

View File

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