Socket
Book a DemoInstallSign in
Socket

babel-plugin-resolve-import

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-resolve-import

解决编译后路径不正确及无法引入的文件类型的Babel插件

0.0.1
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-resolve-import tnpm JavaScript Style Guide

项目地址

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

Keywords

babel

FAQs

Package last updated on 22 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.