vue-tailwind icon indicating copy to clipboard operation
vue-tailwind copied to clipboard

Build for production with Vite?

Open seabasss opened this issue 2 years ago • 9 comments

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!

seabasss avatar Dec 16 '22 06:12 seabasss

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

JhumanJ avatar Jan 14 '23 04:01 JhumanJ

Here's the line: https://github.com/alfonsobries/vue-tailwind/blob/e35d73405862128cb0cf616e0ab3a80128794411/src/base/Component.ts#L38

JhumanJ avatar Jan 14 '23 04:01 JhumanJ

Any news? @alfonsobries

infinitodk avatar Jan 17 '23 21:01 infinitodk

Any news?

RA9 avatar Mar 26 '23 09:03 RA9

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

niklaz avatar May 05 '23 10:05 niklaz

Bit hacky, isn't it?

infinitodk avatar May 05 '23 10:05 infinitodk

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

niklaz avatar May 05 '23 10:05 niklaz

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

ianjamieson avatar May 30 '23 12:05 ianjamieson

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.

paullexen avatar Aug 30 '23 15:08 paullexen