convert the referenced directory to all files under the reference directory
//转换前的代码
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
}
npm install --save-dev babel-plugin-require-all
.babelrc
{
"plugins": ["require-all"]
}
babel --plugins require-all script.js
require("babel-core").transform("code", {
plugins: ["require-all"]
});