JuniorTour / vue-template-babel-compiler

Enable Optional Chaining(?.), Nullish Coalescing(??) and many new ES syntax for Vue.js SFC based on Babel
https://www.npmjs.com/package/vue-template-babel-compiler
118 stars 9 forks source link

[Bug] [BABEL] Note: The code generator has deoptimised the styling #37

Closed hymair closed 2 years ago

hymair commented 2 years ago
ERROR  [BABEL] Note: The code generator has deoptimised the styling of <PROJECT-PATH>/VueTemplateBabelCompiler as it exceeds the max of 500KB.

Info

Only used optional chaining. Exactly 23 occurrences total in 4 different files.

Extra

hymair commented 2 years ago

Adding this did not fix the error.

// nuxt.config.ts
build: {
  babel: {
    compact: true,
  },
  loaders: {
    vue: {
      compiler: require('vue-template-babel-compiler'),
    },
  },
}
JuniorTour commented 2 years ago

🤔 This msg seems to be just a warning from babel?

Refer: https://stackoverflow.com/questions/35192796/babel-note-the-code-generator-has-deoptimised-the-styling-of-app-js-as-it-exc


Does it have any negative impact for you?

If you don't want to see this warning msg, you can add compact: true to babel options like this: https://github.com/JuniorTour/vue-template-babel-compiler/blob/main/doc/Usage.md#1-babel-options-customization


// nuxt.config.js
export default {
  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    loaders: {
      vue: {
        compilerOptions: {
          babelOptions: {
           compact: true,
          },
        },
        compiler: require('vue-template-babel-compiler')
      }
    },
  },
  // ...
}
hymair commented 2 years ago

compact: true hides the error but I had to add @ts-ignore as there was a type error.

Type '{ babelOptions: { compact: true; }; }' is not assignable to type 'CompilerOptions'.
  Object literal may only specify known properties, and 'babelOptions' does not exist in type 'CompilerOptions'.