English | 简体中文
traverse import to global expression babel-plugin-import-to-global
install
npm i -D babel-plugin-import-to-global
// or
yarn add -D babel-plugin-import-to-global
config
.babelrc
{
plugins: ['babel-plugin-import-to-global', {
moduleName: 'A', // moudule name
globalName: 'window', // global var name(default window)
globalAttr: 'a' // global attr name(default moduleName)
}]
}
example
import AM from "A";
output:
const AM = window.a;