Tailwind css 在 Vue Web 组件中不起作用

Elv*_*vis 6 web-component vue.js tailwind-css

我有一个 Vue Web 组件。当我将其构建为普通的 Vue 组件时,一切正常。然而,当我将其转换为 Vue Web 组件时,它就失去了所有 Tailwind 样式。提前感谢您的帮助。

tailwind.config.js

module.exports = {
  content: [
    "./index.html",
    "./src/**/*.{vue,js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {
      colors: {
      },
    },
  },
  plugins: [
  ],
}

Run Code Online (Sandbox Code Playgroud)

顺风.css

@tailwind base;
@tailwind components;
@tailwind utilities;
Run Code Online (Sandbox Code Playgroud)

和我的 vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue({
    template: {
      compilerOptions: {
        // treat all tags with a dash as custom elements
        isCustomElement: (tag) => tag.includes('-')
      }
    }
  })],
  build: {
    lib: {
      entry: './src/entry.js',
      formats: ['es','cjs'],
      name: 'web-component',
      fileName: (format)=>(format === 'es' ? 'index.js' : 'index.cjs')
    },
    sourcemap: true,
    target: 'esnext',
    minify: false
  }
})
Run Code Online (Sandbox Code Playgroud)

Elv*_*vis 1

无论如何,目前我所做的是将 Tailwind 直接添加到 Web 组件中,并且它可以工作。

<style>
 @import url("../tailwind.css");
</style>
Run Code Online (Sandbox Code Playgroud)