Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import devtools from '@vue/devtools' gets into Vite production build #1961

Closed
segevfiner opened this issue Oct 3, 2022 · 6 comments
Closed

Comments

@segevfiner
Copy link

Version

6.4.3

Browser and OS info

Chrome 105 / macOS 12.6

Steps to reproduce

  1. Create an empty vite project
  2. Add import devtools from '@vue/devtools' &
    if (import.meta.env.MODE === 'development') {
      devtools.connect()
    }
  3. Build the production build. @vue/devtools doesn't get tree shaken and gets into the production build. I have also seen cases of it importing node specific code which leads to an undefined import to emitter.

What is expected?

For it to be tree shaken so it is easy to include @vue/devtools standalone only for dev builds

What is actually happening?

It is not tree shaken


Without it being tree shaken, I will have to manually comment/uncomment it. I haven't found a way to direct it to tree shake @vue/devtools outside of modifying its package.json and adding "sideEffects": false. It still spews a huge amount of eval warnings despite this which I have no idea how to silence.

@segevfiner
Copy link
Author

This rollup plugin can be used as a workaround:

    {
      name: 'vue-devtools-side-effects',
      transform(code, id, options?) {
        if (/@vue\/devtools\/index.js$/.test(id)) {
          return {
            code,
            moduleSideEffects: false,
            map: null,
          };
        }
      },
    },

Although you will still get a lot of eval warnings.

@TechAkayy
Copy link

Same here, and the size it adds to the production build is huge!

@Akryum Akryum closed this as completed in 751edce Oct 10, 2022
@Kilbourne
Copy link

It doesn't get into production build but the eval warnings are still there. Can these warnings be fixed?
The warning is 'Error when using sourcemap for reporting an error: Can't resolve original location of error.
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification' and it shows around 50times for build

@Stanzilla
Copy link

Looking for a solution for this as well

@bernardoadc
Copy link

Found it here:

// vite.config.js
  build: {
    rollupOptions: {
      onwarn: (warning, warn) => (warning.code !== 'EVAL') ? warn(warning) : undefined // suppress eval warnings (@vue/devtools)
    }
  }

@Kilbourne
Copy link

Can someone explain why the warnings appear in prod mode ( for what is used eval in this case?) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants