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

Build for production with Vite? #268

Open
seabasss opened this issue Dec 16, 2022 · 9 comments
Open

Build for production with Vite? #268

seabasss opened this issue Dec 16, 2022 · 9 comments

Comments

@seabasss
Copy link

Has anyone gotten this package to work when building for production with Vite?

It seems like Vite is using two different methods to build for dev and prod (with rollup) and it only works for dev for me.

Thanks for tips!

@JhumanJ
Copy link

JhumanJ commented Jan 14, 2023

Same here! Getting Uncaught TypeError: Vue__default.default.extend is not a function here:
image

@JhumanJ
Copy link

JhumanJ commented Jan 14, 2023

Here's the line:

const Component = Vue.extend({

@infinitodk
Copy link

Any news? @alfonsobries

@RA9
Copy link

RA9 commented Mar 26, 2023

Any news?

@niklaz
Copy link

niklaz commented May 5, 2023

I have solved this issue by installing yarn add @vitejs/plugin-vue2 and adding it in vite.config.js:

 // vite.config.js
import vue from '@vitejs/plugin-vue2'

export default {
  plugins: [vue()]
}

https://github.com/vitejs/vite-plugin-vue2

@infinitodk
Copy link

Bit hacky, isn't it?

@niklaz
Copy link

niklaz commented May 5, 2023

Sure, but it worked for me as a quick fix for now. Of course, for vue v.2.7.x.

@ianjamieson
Copy link
Contributor

ianjamieson commented May 30, 2023

I have solved this issue by installing yarn add @vitejs/plugin-vue2 and adding it in vite.config.js:

This is what I was expecting to work, but I am still getting the same issue where extend is not a function

@paullexen
Copy link

I had this problem and I solved it by adding a plugin to my Vite config that modifies the vue-tailwind code:

Here's the plugin

const modifyVueTailwind = {
    name: 'modifyVueTailwind',
    transform(code, id) {
        if (!/vue-tailwind\/dist\/(vue-tailwind|components)\.js/.test(id)) {
            return
        }

        return code.replace(
            "function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }",
            "function _interopDefaultLegacy (e) { return e && (typeof e === 'object' || typeof e === 'function' ) && 'default' in e ? e : { 'default': e }; }",
        )
    }
}

And then within my plugins array within defineConfig:

plugins: [
    vue(),
    modifyVueTailwind,
    // additional plugins ... 
]

You may need to modify the regex in the transform function based on how you're importing the tailwind library.

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

7 participants