Skip to content

pzmosquito/eslint-import-resolver-vite

Repository files navigation

eslint-import-resolver-vite

Vite module resolution plugin for eslint-plugin-import and eslint-plugin-import-x. This plugin will resolve the resolve.alias option.

Installation

npm install --save-dev eslint-import-resolver-vite

How to use

Vite config file

export const viteConfigObj = {
    resolve: {
        alias: {
            _: path.resolve(__dirname, "src")
        }
    },
};

ESLint config file

NOTE:

  • Since ESLint requires rules to be synchronous, Vite's ResolvedConfig API cannot be utilized.
  • This plugin accepts a Vite config object to accommodate various setups, e.g. CJS, ESM, or mixed.
// for using `eslint-plugin-import`
module.exports = {
    settings: {
        "import/resolver": {
            vite: {
                viteConfig: require("./vite.config").viteConfigObj, // named export of the Vite config object.
            }
        }
    }
}


// for using `eslint-plugin-import-x` resolver interface v3
const { createViteImportResolver } = require("eslint-import-resolver-vite");

module.exports = {
    settings: {
        "import-x/resolver-next": [
            createViteImportResolver({
                viteConfig: require("./vite.config").viteConfigObj, // named export of the Vite config object.
            })
        ]
    }
}

About

Vite module resolution plugin for eslint-plugin-import.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •