ly525 / blog

My personal blog / 个人博客(小小鲁班的技术口袋)
https://github.com/ly525/blog/issues
MIT License
45 stars 4 forks source link

[知识体系] babel #410

Open ly525 opened 4 years ago

ly525 commented 4 years ago

preset(从右边到左)

{ "presets": ["env"] } # babel-preset-env { "presets": ["vue"] } # babel-preset-vue { "presets": ["@vue/app"] } { "presets": ["@vue/jsx"] } # @vue/jsx { "presets": ["@vue/cli-plugin-babel"] } { "presets": ["@vue/babel-preset-app"] } { "presets": ["@vue/babel-preset-jsx"] } # Babel7


## plugin(从左到右)
```bash
{ "plugins": ["@vue/babel-plugin-jsx"] }  # jsx for vue3

# vue2
# babel-plugin-transform-vue-jsx(3.x for Babel 6,4.x for babel7)
# @vue/babel-plugin-transform-vue-jsx(Babel7)
{ "plugins": ["transform-vue-jsx"] }  # 
const babel = require('@babel/core')

const code = `
const sayHi = () => {
  console.log('hello babel')
}

sayHi()
`

const optionsObject = {}
const result = babel.transform(code, optionsObject)
console.log(result)