vite-plugin-vue2 icon indicating copy to clipboard operation
vite-plugin-vue2 copied to clipboard

Support/Enhancement for other Babel Plugins - Null Coalescing Operator, Optional Chaining and others

Open Kaustix opened this issue 3 years ago • 5 comments

Requesting an Enhancement or Support for adding the bellow babel plugin support for vue templates. I know there's a fork of this project that has included support for these https://github.com/pedro-gilmora/vite-vue2, however it would be better if these were added out the box as the fork seems to be behind and not being actively supported. Is this something that can be added to vue templates?

@babel/plugin-proposal-nullish-coalescing-operator @babel/plugin-proposal-optional-chaining @babel/plugin-transform-arrow-functions @babel/plugin-transform-block-scoping @babel/plugin-transform-destructuring @babel/plugin-transform-parameters @babel/plugin-transform-spread

Kaustix avatar Jan 04 '22 21:01 Kaustix

Here is a solution if you are using a package manager which supports resolutions in package.json

{
  "resolutions": {
    "vue-template-es2015-compiler": "npm:[email protected]"
  }
}

NikhilVerma avatar Mar 17 '22 18:03 NikhilVerma

@NikhilVerma which bundlers do this?

souljorje avatar Mar 17 '22 18:03 souljorje

@souljorje Apologies I meant package manager. so

  1. Yarn
  2. pnpm
  3. npm with https://www.npmjs.com/package/npm-force-resolutions

NikhilVerma avatar Mar 18 '22 00:03 NikhilVerma

npm install vue-template-babel-compiler -D

createVuePlugin({
    //........
    vueTemplateOptions: {
      compiler: require('vue-template-babel-compiler'),
      compilerOptions: {
        whitespace: 'preserve'
      }
    }
  })

Optional chaining in templates does not seem to work

[vite] Internal server error: invalid expression: Unexpected token '.'

caocos avatar Apr 09 '22 08:04 caocos

I've made a PR to fix this issue - https://github.com/underfin/vite-plugin-vue2/pull/179

NikhilVerma avatar Apr 09 '22 08:04 NikhilVerma