连尤雨溪都没实现!用 babel 编译 vue.js <template> 支持 Optional Chaining
文章目录
GitHub Repo: vue-template-babel-compiler
使用 Babel 为 Vue.js SFC 启用 Optional Chaining(?.), Nullish Coalescing(??) 等诸多 ES 新语法。
示例

特性
- vue-template-compiler && vue-template-es2015-compiler 的所有功能
- 新语法:
Optional Chaining,Bigint,nullish coalescingand more - 自定义语法、babel 插件等等...
用法
1. 安装
npm install vue-template-babel-compiler --save-dev2. 配置
1. Vue-CLI
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module
.rule('vue')
.use('vue-loader')
.tap(options => {
options.compiler = require('vue-template-babel-compiler')
return options
})
}
}2. Nuxt.js
// nuxt.config.js
export default {
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
loaders: {
vue: {
compiler: require('vue-template-babel-compiler')
}
},
},
// ...
}3. Webpack
// your webpack.config.js where config vue-loader
module.exports = {
// ...
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compiler: require('vue-template-babel-compiler')
}
}
]
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论