mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat: better aliases
This commit is contained in:
parent
71faf7cae3
commit
ea1b5ae10f
@ -47,24 +47,12 @@ export default function webpackBaseConfig ({ isClient, isServer }) {
|
|||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.json', '.vue', '.ts'],
|
extensions: ['.js', '.json', '.vue', '.ts'],
|
||||||
alias: {
|
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.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'), // 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'), // 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')
|
|
||||||
},
|
},
|
||||||
modules: [
|
modules: [
|
||||||
join(this.options.rootDir, 'node_modules'),
|
join(this.options.rootDir, 'node_modules'),
|
||||||
|
@ -96,14 +96,7 @@ export function r () {
|
|||||||
let args = Array.prototype.slice.apply(arguments)
|
let args = Array.prototype.slice.apply(arguments)
|
||||||
let lastArg = _.last(args)
|
let lastArg = _.last(args)
|
||||||
|
|
||||||
if (lastArg.includes('@')) {
|
if (lastArg.includes('@') || 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('~', '@/'))
|
|
||||||
return wp(lastArg)
|
return wp(lastArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,21 +100,16 @@ export default class Nuxt extends Tapable {
|
|||||||
|
|
||||||
resolvePath (path) {
|
resolvePath (path) {
|
||||||
// Try to resolve using NPM resolve path first
|
// Try to resolve using NPM resolve path first
|
||||||
// Fixes problems with scopped modules
|
|
||||||
try {
|
try {
|
||||||
let resolvedPath = require.resolve(path)
|
let resolvedPath = require.resolve(path)
|
||||||
return resolvedPath
|
return resolvedPath
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Just continue
|
// Just continue
|
||||||
}
|
}
|
||||||
|
// Shorthand to resolve from project dirs
|
||||||
// Shorthand to resolve from project srcDir
|
if (path.indexOf('@@') === 0 || path.indexOf('~~') === 0) {
|
||||||
if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
|
return join(this.options.rootDir, path.substr(2))
|
||||||
if (path.indexOf('~') === 0) {
|
} else if (path.indexOf('@') === 0 || path.indexOf('~') === 0) {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn('[nuxt] Aliases using `~` are deprecated, please use `@/` instead.',
|
|
||||||
path, '->', path.replace('~/', '@/').replace('~', '@/'))
|
|
||||||
}
|
|
||||||
return join(this.options.srcDir, path.substr(1))
|
return join(this.options.srcDir, path.substr(1))
|
||||||
}
|
}
|
||||||
return resolve(this.options.srcDir, path)
|
return resolve(this.options.srcDir, path)
|
||||||
|
Loading…
Reference in New Issue
Block a user