Babel plugin for disallowing imports from a source
npm install --save-dev babel-plugin-disallow-imports
This is useful when you want to disallow some imports from specific files or allow them in only some files.
.babelrc
{
"plugins": [
[
"babel-plugin-disallow-imports",
{
"properties": [
{
"disallowedImport": "module/to/import",
"disallowedImporters": ["fileName"],
"message": "Oups ! `module/imported` should not be imported in filename"
}
]
}
],
]
}
fileName.js
import something from 'module/to/import'
output
Error: /path/to/file/fileName.js: Oups ! `module/imported` should not be imported in filename
The plugin supports a properties
array with following options:
interface Property {
// The error message that should be displayed
message: string
// The module that you want to disallow importing
disallowedImport: string
// Files that you want to disallow importing from
disallowedImporters?: string[]
// Files that you want to allow importing `disallowedImport` module from. Importing `disallowedImport` from other files will throw the error message
allowedImporters?: string[]
}
MIT