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

Building with esbuild minifier produces the same css twice #2144

Closed
3 tasks done
sheremet-va opened this issue Feb 21, 2021 · 11 comments
Closed
3 tasks done

Building with esbuild minifier produces the same css twice #2144

sheremet-va opened this issue Feb 21, 2021 · 11 comments

Comments

@sheremet-va
Copy link
Member

sheremet-va commented Feb 21, 2021

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

When building with minify: 'esbuild', production code has the same CSS twice. One in a js chunk, and the second one in css chunk.

Reproduction

  1. create project with vue-ts template npm init @vitejs/app esbuild-bug --template vue-ts
  2. update vite.config.ts as follows:
export default defineConfig({
  plugins: [vue()],
  build: {
    minify: 'esbuild'
  }
})
  1. run npm run build
  2. open /dist/assets/index.[hash].js
  3. you will see non-minified CSS
  4. open index.[hash].css
  5. you will see the same css, but minified

System Info

  • vite version: 2.0.1
  • Operating System: MacOS Big Sur 11.2.1
  • Node version: 14.4
  • Package manager (npm/yarn/pnpm) and version: 6.14.4
@edison1105
Copy link
Member

edison1105 commented Feb 21, 2021

maybe it's not a bug.
just an unused variable in production mode.

image

@sheremet-va
Copy link
Member Author

@edison1105 I think producing giant unused variable is a bug. It even contains comments if there are some.

As far as I know, Vite uses it's own plugin for esbuild to parse .vue files, so I guess it's Vite problem?

@edison1105
Copy link
Member

so I guess it's Vite problem?

I agree, the unused variable should remove.

@yyx990803
Copy link
Member

Related: #2148

We may remove the default export for CSS imports unless an explicit query is used.

@Dreamacro
Copy link

Dreamacro commented Mar 28, 2021

This is also reproduced in the use of react

import './style.css'

export function Component() {
    return <div>foo</div>
}

and bundle contains additional unnecessary css strings

@Dreamacro
Copy link

seems it's already fixed on #3570

@Dreamacro
Copy link

it happened again after 91eb2a6 🌚

@sheremet-va
Copy link
Member Author

Is it fixed? Can we close the issue?

@Dreamacro
Copy link

@sheremet-va it's still no fixed on the latest vite (v2.4.4)

I use a workaround plugin to make minify: 'esbuild' work correctly

{
    plugins: [
        // other plugin
        {
            name: 'remove-css-in-js',
            enforce: 'post',
            transform (_, id) {
                if (id.endsWith('.scss') || id.endsWith('.css')) {
                    return ''
                }
            },
        },
    ],
    build: {
        minify: 'esbuild',
    },
}

@Dreamacro
Copy link

seems it's already fixed on 2.6.0-beta.0 (3e3c203)

@patak-dev
Copy link
Member

Thanks for the heads up @Dreamacro!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants