babel-cli命令行

380 阅读1分钟

安装

  • @babel/cli
  • @babel/core
  • @babel/preset-env

参数说明

    1. -d,--out-dir [out] 指定输入目录,编译输出到指定目录
    • npx babel src -d lib
    1. --source-maps [true,false,inline,both] 增加source map文件
    • npx babel src -d lib --source-maps
    1. -o,--out-file [out] 指定输入文件或目录,合并编译输出到一个新文件
    • npx babel index.js -o compile.index.js
    1. -w,--watch 监听文件修改并执行编译
    • npx babel src -d lib --source-maps --watch
    1. --ignore 忽略指定正则文件(package.json中/需转义)
    • npx babel src -d lib --source-maps --ignore "node_modules/**/*.js"
    1. --copy-files 拷贝文件(可通过其方式实现)
    • npx babel src -d lib --copy--files
    1. 通过管道输入文件
    • npx babel src -o compiled.js<index.js -f index.js --source-maps
    1. --plugins 使用插件
    • npx babel src -d lib --plugins=@babel/plugin-transform-arrow-functions
    1. --presets 预设
    • npx babel src -d lib --presets=@babel/preset-env
    1. --no-babelrc 忽略.babelrc,并通过命令行参数执行构建流程
    • npx babel --no-babelrc src -d lib --plugins=@babel/plugin-transform-arrow-functions