Недавно я начал новый проект с Nuxt.js вместе с Typescript.Я устанавливаю псевдонимы внутри nuxt.config.ts
, например:
const config: NuxtConfiguration = {
.....
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
// Run ESLint on save
if (ctx.isDev && ctx.isClient && config.module) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue|ts)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
});
}
if (config.resolve && config.resolve.alias) {
config.resolve.alias['@'] = path.resolve(__dirname, 'src');
config.resolve.alias['~'] = path.resolve(__dirname, 'src');
}
},
}
};
export default config;
Внутри nuxt, все работает нормально.Я могу импортировать компоненты без проблем.Однако мой Eslint не может разрешить путь.
Это мой Eslint-файл:
const path = require('path');
module.exports = {
extends: [
'@nuxtjs',
],
env: {
browser: true,
node: true,
},
parserOptions: {
parser: '@typescript-eslint/parser',
},
plugins: [
'@typescript-eslint',
],
settings: {
'import/resolver': {
webpack: {
config: 'webpack.config.js',
},
},
},
}
Это мой webpack.config.js.
const path = require('path');
module.exports = {
resolve: {
extensions: ['.js', '.json', '.vue', '.scss'],
root: path.resolve(__dirname, 'src'),
alias: {
'@': path.resolve(__dirname, 'src'),
'~': path.resolve(__dirname, 'src'),
},
},
};
Isчто-то мне не хватает?