Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel@7 #111

Open
magicdawn opened this issue Sep 26, 2018 · 3 comments
Open

babel@7 #111

magicdawn opened this issue Sep 26, 2018 · 3 comments

Comments

@magicdawn
Copy link
Owner

No description provided.

@magicdawn
Copy link
Owner Author

config

  • babel.config.js 全局配置
  • .babelrc / .babelrc.js / package.json#babel 被编译的文件相对的配置

.babelrc 加载限制

  • 碰到一个有 package.json 文件的文件夹, 则停止搜寻 .babelrc
  • 被babel 处理的文件所在的包必须在 options.babelrcRoots 里边

跟配置相关的 option
https://babeljs.io/docs/en/options#config-loading-options

  • configFile 设置 babel.config.js 的别名

  • root + rootMode 配置项目根文件夹 和 决定 babelrcRoots 的默认值,

    • rootMode = "root", 最终 root = options.root
    • rootMode = "upward", 最终 root = options.root 往上找, 直到找到 babel.config.js 为止, 找不到报错
    • rootMode = "upward-optional", 往上找, 找不到, fallback 到 options.root
  • babelrc: 禁用掉 .babelrc 的加载逻辑

  • babelrcRoots 因为 .babelrc 的加载不能跨过包的界限, 默认 babelrcRoots = [最终root]

This option allows users to provide a list of other packages that should be considered "root" packages when considering whether to load .babelrc files.

https://babeljs.io/docs/en/options#babelrcroots

@magicdawn
Copy link
Owner Author

babel7 主要更新

  • babel-preset-es201x 移除了, 用于支持 @babel/preset-env, 不带 targets使用 env preset, 相当于把之前的 es2015 / es2016 ... 都使用上
  • @babel/preset-stage-x 有 deprecate warn, 需要自己去引用 @babel/plugin-proposal-xxx

@magicdawn
Copy link
Owner Author

magicdawn commented Sep 26, 2018

@babel/preset-env

useBuiltin

这是个独立的功能, 用于处理 polyfill 相关的功能

  • false: 什么都不干
  • entry: 将 import '@babel/polyfill' 展开
  • usage: 在每个需要 polyfill 的地方去 import 单个 polyfill, 这样不需要再 app.js 最前面添加 'import babel-polyfill'

Web Application 来说, false 即可

include / exclude

https://babeljs.io/docs/en/babel-preset-env#include
可以方便的关掉某一个 plugin 了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant