此类博客不多BB,复制粘贴运行一把梭。
1.package.json
{
"scripts": {
"script": "node entry.js"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/register": "^7.0.0"
}
}
2.entry.js
require('@babel/register')({
plugins: ['@babel/plugin-transform-modules-commonjs']
});
require('./script'); // 脚本入口
3.script.js
import zhCN from './zh-CN';
import enUS from './en-US';
var fs = require("fs");
// xxx
4.运行
npm run script