Node script is compatible with running ES6 modular specification code [daily tips]

There are not many BBs in this type of blog, copy and paste to run a shuttle.

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. Run

npm run script

Guess you like

Origin blog.csdn.net/jw2268136570/article/details/109291617