feat: better aliases

This commit is contained in:
Pooya Parsa 2017-07-04 18:51:41 +04:30
parent 71faf7cae3
commit ea1b5ae10f
3 changed files with 9 additions and 33 deletions

View File

@ -47,24 +47,12 @@ export default function webpackBaseConfig ({ isClient, isServer }) {
resolve: {
extensions: ['.js', '.json', '.vue', '.ts'],
alias: {
'@@': join(this.options.rootDir),
'@': join(this.options.srcDir),
'@static': join(this.options.srcDir, 'static'),
'@assets': join(this.options.srcDir, 'assets'),
'@plugins': join(this.options.srcDir, 'plugins'),
'@pages': join(this.options.srcDir, 'pages'),
'@components': join(this.options.srcDir, 'components'),
'@middleware': join(this.options.srcDir, 'middleware'),
// Legacy support
'~': join(this.options.srcDir),
'~~': join(this.options.rootDir),
'@': join(this.options.srcDir),
'@@': join(this.options.rootDir),
'static': join(this.options.srcDir, 'static'), // use in template with <img src="~static/nuxt.png" />
'~static': join(this.options.srcDir, 'static'),
'assets': join(this.options.srcDir, 'assets'), // use in template with <img src="~assets/nuxt.png" />
'~assets': join(this.options.srcDir, 'assets'),
'~plugins': join(this.options.srcDir, 'plugins'),
'~pages': join(this.options.srcDir, 'pages'),
'~components': join(this.options.srcDir, 'components'),
'~middleware': join(this.options.srcDir, 'middleware')
'assets': join(this.options.srcDir, 'assets') // use in template with <img src="~assets/nuxt.png" />
},
modules: [
join(this.options.rootDir, 'node_modules'),

View File

@ -96,14 +96,7 @@ export function r () {
let args = Array.prototype.slice.apply(arguments)
let lastArg = _.last(args)
if (lastArg.includes('@')) {
return wp(lastArg)
}
if (lastArg.includes('~')) {
// eslint-disable-next-line no-console
console.warn('[nuxt] Aliases using `~` are deprecated, please use `@/` instead.',
lastArg, '->', lastArg.replace('~/', '@/').replace('~', '@/'))
if (lastArg.includes('@') || lastArg.includes('~')) {
return wp(lastArg)
}

View File

@ -100,21 +100,16 @@ export default class Nuxt extends Tapable {
resolvePath (path) {
// Try to resolve using NPM resolve path first
// Fixes problems with scopped modules
try {
let resolvedPath = require.resolve(path)
return resolvedPath
} catch (e) {
// Just continue
}
// Shorthand to resolve from project srcDir
if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
if (path.indexOf('~') === 0) {
// eslint-disable-next-line no-console
console.warn('[nuxt] Aliases using `~` are deprecated, please use `@/` instead.',
path, '->', path.replace('~/', '@/').replace('~', '@/'))
}
// Shorthand to resolve from project dirs
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
return join(this.options.rootDir, path.substr(2))
} else if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
return join(this.options.srcDir, path.substr(1))
}
return resolve(this.options.srcDir, path)