vue 批量处理import导入组件为require()方式
/***** */var fs = require("fs");var path = require("path");fs.readFile(__dirname + '/test2.js', {flag: 'r+', encoding: 'utf8'}, function callback(err, data) {var dataReg = data.split('/*\n'...
·
/* * * * * */ var fs = require("fs"); var path = require("path"); fs.readFile(__dirname + '/test2.js', {flag: 'r+', encoding: 'utf8'}, function callback(err, data) { var dataReg = data.split('/*\n' + '*\n' + '*\n' + '*\n' + '* */')[1].split('\n'), dataFinall = [],datatest=[]; dataReg.map((item, index) => { if (item.indexOf('import') == 0) { datatest.push(item) dataFinall.push({name: item.split('import')[1].split('from')[0], url: item.split('import')[1].split('from')[1]}) } }); console.log(dataReg) console.log(datatest) var dataInsert = ''; dataFinall.map(item => { dataInsert += `const${item.name}= (resolve) => { import(${item.url}).then((module) => { resolve(module) }) }\n` }); fs.writeFile(__dirname + '/success.js', dataInsert, {flag: 'a'}, function (err) { if (err) { console.error(err); } else { console.log('写入成功'); } }); });
更多推荐
已为社区贡献3条内容
所有评论(0)