rspack icon indicating copy to clipboard operation
rspack copied to clipboard

rspack.SwcCssMinimizerRspackPlugin generated wrong css content

Open guomio opened this issue 1 year ago • 3 comments

System Info

System:
    OS: Linux 6.2 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (2) x64 AMD EPYC 7763 64-Core Processor
    Memory: 5.20 GB / 7.74 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.10.0 - ~/nvm/current/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 10.2.3 - ~/nvm/current/bin/npm
    pnpm: 8.11.0 - ~/nvm/current/bin/pnpm
  npmPackages:
    @rspack/cli: latest => 0.4.5 
    @rspack/core: latest => 0.4.5

Details

SwcCssMinimizerRspackPlugin changes -160deg to 200deg etc., which causes wrong behavior

input

.text {
    color: blue;
    background: conic-gradient(
        from -160deg at 50% 50%,
            #e92a67 0deg,
            #a853ba 120deg,
            #2a8af6 240deg,
            #e92a67 360deg
        );
}

wrong output(rspack+rspack.SwcCssMinimizerRspackPlugin)

.text{color:blue;background:conic-gradient(from 200deg at 50%50%,#e92a67 0deg,#a853ba 120deg,#2a8af6 240deg,#e92a67 0deg)}

WX20240103-153140@2x

output(webpack+CssMinimizerPlugin)

.text{background:conic-gradient(from -160deg at 50% 50%,#e92a67 0deg,#a853ba 120deg,#2a8af6 240deg,#e92a67 1turn);color:blue}head{--webpack-rspack-repro-src_render_js:\.\/src\/render\.css}

WX20240103-153107@2x

Reproduce link

https://github.com/guomio/rspack-issue-SwcCssMinimizerRspackPlugin

Reproduce Steps

  1. git clone https://github.com/guomio/rspack-issue-SwcCssMinimizerRspackPlugin
  2. npm i
  3. npm run build
  4. see the output

guomio avatar Jan 03 '24 07:01 guomio

It probably caused by SWC CSS parser, can you try using other css minimizer

JSerFeng avatar Jan 03 '24 12:01 JSerFeng

It probably caused by SWC CSS parser, can you try using other css minimizer

@JSerFeng Indeed, webpack with the following config resulted in the same output. Other minimizers looks ok

optimization: {
    minimize: true,
    minimizer: [
      isRunningWebpack
        ? new CssMinimizerPlugin({ minify: CssMinimizerPlugin.swcMinify })
        : new rspack.SwcCssMinimizerRspackPlugin()
    ]
  }

guomio avatar Jan 04 '24 06:01 guomio

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] avatar Apr 22 '24 07:04 stale[bot]

Fixed by https://github.com/swc-project/swc/pull/9072

And it is recommended to use LightningCssMinimizerRspackPlugin, Rspack will enable LightningCssMinimizerRspackPlugin by default in v1.0.0, see https://www.rspack.dev/plugins/rspack/lightning-css-minimizer-rspack-plugin

chenjiahan avatar Jun 26 '24 06:06 chenjiahan