question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

seek a solution about the dist of vueuse that is not escaped from es6 to es5

See original GitHub issue

Hello, antfu! I encountered a problem that I found the dist of vueuse didn’t transfrom es6 to es5。So when i installed vueuse in my project and built it, the packaging product of my project contains es6 grammar such as constArrow function .etc。

I have a question that why the code in the npm package and cdn link of vueuse is not translated intoes5 。I think perhaps installing npm packages directly or introducing cdn links in some of the company’s projects will cause problems with low-version models so that we cannot use vususe in out projects。

image

I have tried to solve this question by myself。I think the config about babel in babel.config.js and vue.config.js is effective, because the code in my project has all successfully been translated into es5。 The version of my babel is >7, I wonder if it is my babel that does not translate the 3rd library in node_modules, I added it into the config.module, such as config.module.include.add('/node_modules/@vueuse'), but still failed。

Here is the part of the config of my vue.config.js and babel.config.js:

// vue.config.js
    config.module
      .rule('js')
      .rule('vue')
      .include
      .add('/packages')
      .add('/examples')
      .add('/node_modules/@vueuse')
      .end()
      .use('babel')
      .loader('babel-loader')
      .tap((options) => options);
// babel.config.js
module.exports = {
  presets: [
    ['@vue/cli-plugin-babel/preset', {
      useBuiltIns: 'usage',
    }],
  ],
  plugins: [
    [
      '@babel/plugin-transform-runtime', {
        corejs: 3,
      },
    ],
  ],
};

I really hope to find a solution from you, thank you! 😁

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
userquincommented, Jun 1, 2021

@PaulChess I use this setup with vue-cli-service, but not tested with @vueuse, maybe you only need to add transpileDependencies on vue.config.js:

  • install babel polyfill as dev dependency, for example: "@babel/polyfill": "^7.0.0-beta.49"
  • add babel.config.js to the root directory of the project (you already have it):
module.exports = {
  "presets": [
    ["@vue/app", {
        "useBuiltIns": "entry"
    }],
    ["@babel/preset-env", {
      "modules": false
    }]
  ]
};
  • enable modern flag on package.json: "build": "vue-cli-service build --modern"
  • add import "@babel/polyfill"; at top of main.js.
  • add transpileDependencies entry on vue.config.js file, for example I transpile vuetify, just include there @vueuse packages you use:
module.exports = {
  transpileDependencies: ["vuetify"],
  ...
2reactions
PaulChesscommented, Jun 2, 2021

@userquin Thank you for your help! I have just tried the method you provided, it works! I forgot to add transpileDependencies option in my vue.config.js. So we can indeed compile vueuse in our projects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES5 vs ES6 ( With example code ). We have came so far
Manipulating objects in ES6 vs ES5​​ Let's jump to the code and try to merge two objects in ES5. We have to merge...
Read more >
"Failed to resolve module specifier "vue"" - Stack Overflow
npm run build (result is available inside the ./dist folder of your project. Also, you should import Vue like this. import Vue from...
Read more >
vuejs/vue - Gitter
Now I'm getting data from server and passing it to Article.vue component and truncating it. I need to reproduce this data in modal....
Read more >
ECMAScript 6 Tools Awesome - DirDev.com
Transpilers. Babel - Turn ES6+ code into vanilla ES5 with no runtime; Traceur compiler - ES6 features > ES5. Includes classes, generators, promises, ......
Read more >
A curated list of awesome things related to Vue.js - Gitee
Get your event up and running in no time. Made with Vue and Go. PNGK - Official website for a consultancy company working...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found