A build-time vite plugin that can check circular imports, self-introductions, is compatible with dynamic imports or static imports, and has nothing to do with the front-end framework
// Configure the output path,
// a scan report will be generated to the specified path
export default defineConfig({
plugins: [
vue(),
circleDependency({
outputFilePath: './circleDep'
})
],
})
// Without any configuration, it will be printed on the console
export default defineConfig({
plugins: [
circleDependency()
],
})
npm i -D vite-plugin-circular-dependency
// yarn add --dev vite-plugin-circular-dependency
// pnpm i --dev vite-plugin-circular-dependency
Please use this plugin when building
In your vite.config.(js|ts)
import the plugin and register it.
import { defineConfig } from 'vite'
import circleDependency from 'vite-plugin-circular-dependency'
export default defineConfig({
plugins: [
circleDependency()
],
})
export interface Options {
/**
* Rules to include transforming target.
*
* @default [/\.[jt]sx?$/, /\.vue\??/]
*/
include?: FilterPattern
/**
* Rules to exclude scan target.
*
* @default [/node_modules/, /\.git/]
*/
exclude?: FilterPattern
/**
* The file address of the scan result output, the default console print
*/
outputFilePath?: string
/**
* Whether to throw an error when a circular import exists
*
* @default true
*/
circleImportThrowErr?: boolean
/**
* Format the path of the output node.
* By default, vite.config will be used as the root path to generate a relative path
*
* @default function
*/
formatOutModulePath?: (path: string) => string
/**
* The result of formatted output
* will also affect the data format in the console print or output file
*
* @default (data: CircleData) => data
*/
formatOut?: (data: CircleData) => any
}