Skip to content

Convert the referenced directory to all files under the reference directory 把引用的目录转换成引用目录下面的所有文件

Notifications You must be signed in to change notification settings

dushaobindoudou/babel-plugin-require-all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-require-all

convert the referenced directory to all files under the reference directory

Use in javascript source code

requireAll('dir','splitDir')

dir: 需要引用的资源目录
splitDir: 生成后需要去掉的目录

Demo

//转换前的代码
const imgs = requireAll('./imgs');// ./imas/a.png ./imgs/b.png


//转换后的代码
const $imgs_a = require('./imgs/a.png');
const $imgs_b = require('./imgs/b.png');
const imgs = {
    $imgs_a:$imgs_a,
    $imgs_b:$imgs_b
}


//转换前的代码
const imgs = requireAll('./imgs','./imgs');// ./imas/a.png ./imgs/b.png


//转换后的代码
const $a = require('./imgs/a.png');
const $b = require('./imgs/b.png');
const imgs = {
    $a:$a,
    $b:$b
}

Installation

npm install --save-dev babel-plugin-require-all

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["require-all"]
}

Via CLI

babel --plugins require-all script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["require-all"]
});

About

Convert the referenced directory to all files under the reference directory 把引用的目录转换成引用目录下面的所有文件

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published