diff --git a/bin/nuxt-build b/bin/nuxt-build index 48530be037..1c4fc996ba 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -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() diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 745d718c8f..bfea884332 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -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 } }) diff --git a/lib/core/module.js b/lib/core/module.js index 1ea7ed6ca1..0a87757d37 100755 --- a/lib/core/module.js +++ b/lib/core/module.js @@ -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) - } + handler = require(this.nuxt.resolvePath(src)) } // Validate handler diff --git a/lib/core/nuxt.js b/lib/core/nuxt.js index ce7f7227a6..a3eb03c08c 100644 --- a/lib/core/nuxt.js +++ b/lib/core/nuxt.js @@ -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) {