关于vue.js:连尤雨溪都没实现用-babel-编译-vuejs-template-支持-Optional-Chaining

12次阅读

共计 888 个字符,预计需要花费 3 分钟才能阅读完成。

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 coalescing and more
  • 自定义语法、babel 插件等等 …

用法

1. 装置

npm install vue-template-babel-compiler --save-dev

2. 配置

1. Vue-CLI

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.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')
        }
      }
    ]
  }
}

欢送 Issues && PR.

正文完
 0