Skip to content

fix: js/css are minified when both minify.js and minify.css are false#2865

Merged
chenjiahan merged 1 commit intoweb-infra-dev:mainfrom
xc2:fix-minify-options
Jul 10, 2024
Merged

fix: js/css are minified when both minify.js and minify.css are false#2865
chenjiahan merged 1 commit intoweb-infra-dev:mainfrom
xc2:fix-minify-options

Conversation

@xc2
Copy link
Copy Markdown
Collaborator

@xc2 xc2 commented Jul 10, 2024

Summary

This PR fixes the bug that js/css are minified when minify is { js: false, css: false }.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link
Copy Markdown

netlify bot commented Jul 10, 2024

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 935ea4e
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/668e8701128a520008eb6da9
😎 Deploy Preview https://deploy-preview-2865--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 84 (🟢 up 4 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

}

return {
minifyJs: !(minify.js === false || !isProd),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think minify.js can be enabled in dev mode

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimize is always disabled in dev mode before, even when output.minify is true. (btw this function is moved from plugin/minimize.ts)

shall i make minify available in dev mode since this PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, forget it..

@xc2 xc2 marked this pull request as draft July 10, 2024 09:36
@xc2 xc2 marked this pull request as ready for review July 10, 2024 10:22

const { minifyJs, minifyCss, jsOptions, cssOptions } =
parseMinifyOptions(config);
chain.optimization.minimize(minifyJs || minifyCss);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain.optimization.minimize(minifyJs || minifyCss); is set by the basic plugin, should we set it here again?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain.optimization.minimize(minifyJs || minifyCss); is set by the basic plugin, should we set it here again?

it is for a such edge case that pluginBasic is not applied - typically seen in test cases.

actually i'm not sure why it's in pluginBasic

Copy link
Copy Markdown
Member

@chenjiahan chenjiahan Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can also remove the chain.optimization.minimize() from basic plugin.

But this SWC/LightningCSS minimizer plugin is skipped in the webpack mode 😂, so we need to set chain.optimization.minimize() before this if condition.

image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've refined this PR, please check again.

@xc2 xc2 force-pushed the fix-minify-options branch from fc9b5f9 to 41fe50f Compare July 10, 2024 12:17
@xc2 xc2 requested a review from chenjiahan July 10, 2024 12:21
}
const { minify: _minify } = config.output;
const minify =
_minify && typeof _minify === 'object'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use the former implementation because it seems simpler. 😂

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@xc2 xc2 force-pushed the fix-minify-options branch from 41fe50f to 935ea4e Compare July 10, 2024 13:05
@chenjiahan chenjiahan merged commit 7d3e56d into web-infra-dev:main Jul 10, 2024
@chenjiahan
Copy link
Copy Markdown
Member

^_^

@xc2 xc2 deleted the fix-minify-options branch July 11, 2024 06:28
@9aoy 9aoy mentioned this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants