4
头图

GitHub Repo: vue-template-babel-compiler

Use Babel to Vue.js SFC enable Optional Chaining(?.) , Nullish Coalescing(??) and many other new ES syntax.

Example

DEMO

characteristic

  • All functions of vue-template-compiler && vue-template-es2015-compiler
  • New syntax: Optional Chaining , Bigint , nullish coalescing and more
  • Custom syntax, babel plugins, etc...

usage

1. Installation

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

2. Configuration

1. Vue-CLI

Vue-CLI configuration demo project

// 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 configuration demo project

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

Welcome to Issues && PR.


帅到被人砍
275 声望14 粉丝

春日游,杏花吹满头。