English | 简体中文
import.macro
auto import importDeclarationinstall
npm i -D import.macro// oryarn add -D import.macro
unsure you have install babel-plugin-macros
.babelrc
useage
;;;
output:
;_aB;_aB;
custom import
add a config file:
- .babel-plugin-macrosrc
- .babel-plugin-macrosrc.json
- .babel-plugin-macrosrc.yaml
- .babel-plugin-macrosrc.yml
- .babel-plugin-macrosrc.js
- babel-plugin-macros.config.js
- babelMacros in package.json
Configuration is as follows:
// .babel-plugin-macrosrc.jsmoduleexports = importHelper: // import i from 'import.macro' defaultImport: a imports: 'customImport' prefix: '/path/to' // prefix source path isDefaultExport: true // default is true a // before add importDeclaration,transform sourcePath ;
then, you can import customImport
from import.macro
:
;;
output:
;filename;
there are also a default import,you can config it by importHelper.defaultImport.
when start with @, it will compiled to React component
import customImport from 'import.macro';;
会被编译为:
<SomeComponent />