babel-plugin-resolve-import
v0.0.1
Published
解决编译后路径不正确及无法引入的文件类型的Babel插件
Downloads
2
Readme
babel-plugin-resolve-import
项目地址
https://coding.net/u/ncbql/p/babel-plugin-resolve-import/git
转码例子
源代码:
import './img.png'
import style from './index.less'
const style = require('./button.css')
转码后:
实际中 D:\\node
为当前路径
import 'D:\\node\\img.png'
import style from 'D:\\node\\index.less'
const style = require('D:\\node\\button.css')
安装模块
npm install --save-dev babel-plugin-resolve-import
使用方法
Babel配置文件 (.babelrc)
{
"plugins": [
[
"resolve-import",
{
"root": "根目录地址, 默认为当前目录",
"test": "/build", // 被替换掉的路径
"exts": [".css", ".less", ".scss", ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp", ".ico"] // 被替换的文件类型
}
]
]
}
Babel命令行 (babel-cli)
babel index.js --plugins resolve-import
Babel Node.js API
require('babel-core').transform('code', {
plugins: ['resolve-import']
})
协议
MIT