import-js/eslint-plugin-import

Ensure packages are imported the same way (`import "react"` vs `import("react")`)

Open

#2326 aperta il 12 dic 2021

Vedi su GitHub
 (21 commenti) (0 reazioni) (0 assegnatari)JavaScript (1540 fork)batch import
help wantedrule proposal

Metriche repository

Star
 (4946 star)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

import() is used as an indicator that the bundler can create an additional file (code splitting) instead of including the specified dependency in the main bundle.

Unfortunately it's possible that the same dependency is imported statically in another file, therefore either cancelling the effect or perhaps bundling it twice.

// index
import './a.js'
import './b.js'
// a.js
import { React } from 'react';
// b.js
const { React } = await import('react');

Rule request

Is it possible to ensure that a specific dependency is imported the same way across files automatically?

"import/consistent-import-style": "error"

If not automatically, I wish there was a way to enforce a certain import method per-dependency, for example:

"import/enforce-import-style": [
	"error",
	{
		static: ["react"],
		dynamic: ["my-little-heavy-dep"],
	}
]

Guida contributor