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

CSS does not generate in iife build #1077

Closed
imohuan opened this issue Jun 8, 2022 · 7 comments · Fixed by #1217
Closed

CSS does not generate in iife build #1077

imohuan opened this issue Jun 8, 2022 · 7 comments · Fixed by #1217
Labels
bug Something isn't working

Comments

@imohuan
Copy link

imohuan commented Jun 8, 2022

Mode Dev: The normal display
image

Mode Prod: The CSS cannot be obtained
image

main.ts

import css from "uno.css";
console.log("css", css);

vite.config.ts

export default {
  // ...
  plugins: [
    vue(),
    Unocss({
      mode: "global",
      presets: [
        presetUno(),
        presetWind(),
        presetAttributify() as any,
        presetMini(),
        presetScrollbar(),
        presetScalpel({})
      ],
      transformers: [transformerDirectives()],

    });
  ]
}
@antfu
Copy link
Member

antfu commented Jun 8, 2022

Emm why do you want the css string in runtime?

@imohuan
Copy link
Author

imohuan commented Jun 8, 2022

This is for demonstration purposes, not for anything else

@imohuan
Copy link
Author

imohuan commented Jun 8, 2022

If you look at unoCSS compiled CSS, you will find that there is no valid CSS in the packaged compilation

@antfu
Copy link
Member

antfu commented Jun 8, 2022

We are deploying https://uno.antfu.me/ with the latest UnoCSS and we never faced such regression. Please provide a minimal reproduction, thanks.

@imohuan
Copy link
Author

imohuan commented Jun 9, 2022

According to my test: Find the problem, but not sure how to fix it
vite.config.ts

export default defineConfig({
  base: "./",
  plugins: [vue(), Unocss()],
  build: {
    rollupOptions: {
      // !The problem was changing format to Iife
      output: { format: "iife", inlineDynamicImports: true }, 
    },
  },
});

mini-vue.zip

@antfu antfu changed the title Uno becomes invalid after vite is packed CSS does not generate in iife build Jun 9, 2022
@antfu antfu added the bug Something isn't working label Jun 9, 2022
@nieyuyao
Copy link
Contributor

I also have this problem when set output format to umd.

export default defineConfig({
  base: "./",
  plugins: [vue(), Unocss()],
  build: {
    rollupOptions: {
      output: { format: 'umd' }
    },
  },
});

@nieyuyao
Copy link
Contributor

nieyuyao commented Jul 2, 2022

CSS is bundled into js when format are iife, amd or umd. So the css file cannot be generated.

async generateBundle(options, bundle) {
const files = Object.keys(bundle)
const cssFiles = files
.filter(i => i.endsWith('.css'))
if (!cssFiles.length)
return

Should we try to check for js when css doesn't exist at generateBundle ? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants