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

Option to emit component name based on file name with an NODE_ENV check for Vite + Vue based libraries #36

Open
5 of 6 tasks
segevfiner opened this issue Dec 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@segevfiner
Copy link

Related plugins

Description

When building a Vue component library using Vite and this plugin. Component names are not emitted into productions builds of the library. This hinders debugging using the Vue devtools when using such libraries as all components from the library will show as anonymous component.

Suggested solution

Add an option to keep component names in production build gated behind a NODE_ENV check so that they can be stripped during bundling, that way they can be kept when using a library in development mode.

Alternative

Do this manually in each and every Vue file in the library.

Additional context

Hit this with @tiptap/vue-3 but also with our own custom Vite + Vue based libraries.

Validations

@segevfiner
Copy link
Author

So we currently have this:

  define: {
    __VUE_PROD_DEVTOOLS__: JSON.stringify(true),
  },

Which seems to enable this partially. (Is this documented anywhere?)

Which enables this:

if (devToolsEnabled || (devServer && !isProduction)) {
// expose filename during serve for devtools to pickup
attachedProps.push([
`__file`,
JSON.stringify(isProduction ? path.basename(filename) : filename),
])
}

So something like this would do it:

  if (devToolsEnabled || (devServer && !isProduction)) {
    // expose filename during serve for devtools to pickup
    attachedProps.push([
      `__file`,
      JSON.stringify(isProduction ? `process.env.NODE_ENV !== "production" ? ${path.basename(filename)} : void 0` : filename),
    ])
  }

But when devtools are enabled in production the user might want to keep the name even in production, so we need a specific flag for this, this is meant for Vue libraries so they can keep names during development but allow Vite to strip them in production.

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

No branches or pull requests

2 participants