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

chore: Update webpack.config.js #51098

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Conversation

akshitbansal2005
Copy link
Contributor

@akshitbansal2005 akshitbansal2005 commented Oct 2, 2024

Use of eslint-disable:

The first line disables eslint rules for parameter reassignment (/* eslint no-param-reassign: 0 */). Analysis: Reassigning parameters (like webpackConfig) is generally discouraged in JavaScript as it can introduce side effects, making the code harder to understand and maintain. However, it's common in Webpack configurations. If this is unavoidable, the comment is appropriate, but care should be taken to avoid unnecessary reassignments. Dynamic Entry Configuration (addLocales):

The addLocales function modifies the Webpack entry point and output filenames based on whether a minified version is present. Potential Improvement: Instead of directly modifying webpackConfig.entry and webpackConfig.output, you could copy the entry and output to a new object. This avoids direct mutation and improves maintainability. Since this is specific to Webpack configurations and may involve large objects, the performance hit for shallow copying would be minimal. External Dependencies (externalDayjs and externalCssinjs):

These functions ensure that dayjs and @ant-design/cssinjs are externalized. This helps reduce bundle size by relying on global or existing dependencies rather than bundling them into the output. No issues: These configurations are clear and necessary for optimizing the bundle size. Externalizing dependencies is a standard Webpack optimization technique. Conditional Plugins (BundleAnalyzerPlugin, DuplicatePackageCheckerPlugin, etc.):

Plugins such as BundleAnalyzerPlugin, DuplicatePackageCheckerPlugin, and CircularDependencyPlugin are conditionally added based on the environment. This is great for maintaining a clean and modular configuration. Improvement Suggestion: Consider separating the configuration of these plugins into distinct functions. This would improve the separation of concerns and readability. For instance, a function like addPluginsForProduction(config) could be created to handle all plugin-related logic for the production environment. Verbose Plugin Configurations in Non-CI Environments:

The BundleAnalyzerPlugin is configured to generate a report (report.html) when certain environment variables are set, like ANALYZER or CI. No issues: This is a standard way to trigger analysis in non-CI environments, and the configuration is correctly gated behind environment variables. Webpack Optimizations (usedExports):

The config.optimization.usedExports = true; setting is used to enable tree-shaking, reducing bundle size by removing unused exports. No issues: This is an effective optimization to reduce the size of non-minified distribution files. Direct Assignment of Webpack Config:

The final export assigns webpackConfig to the module exports using the spread operator: module.exports = [...webpackConfig];.
No issues: This is appropriate, especially if getWebpackConfig returns an array. Spreading ensures any array returned by getWebpackConfig is flattened, which can prevent unexpected behavior.

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English
🇨🇳 Chinese

Use of eslint-disable:

The first line disables eslint rules for parameter reassignment (/* eslint no-param-reassign: 0 */).
Analysis: Reassigning parameters (like webpackConfig) is generally discouraged in JavaScript as it can introduce side effects, making the code harder to understand and maintain. However, it's common in Webpack configurations. If this is unavoidable, the comment is appropriate, but care should be taken to avoid unnecessary reassignments.
Dynamic Entry Configuration (addLocales):

The addLocales function modifies the Webpack entry point and output filenames based on whether a minified version is present.
Potential Improvement: Instead of directly modifying webpackConfig.entry and webpackConfig.output, you could copy the entry and output to a new object. This avoids direct mutation and improves maintainability. Since this is specific to Webpack configurations and may involve large objects, the performance hit for shallow copying would be minimal.
External Dependencies (externalDayjs and externalCssinjs):

These functions ensure that dayjs and @ant-design/cssinjs are externalized. This helps reduce bundle size by relying on global or existing dependencies rather than bundling them into the output.
No issues: These configurations are clear and necessary for optimizing the bundle size. Externalizing dependencies is a standard Webpack optimization technique.
Conditional Plugins (BundleAnalyzerPlugin, DuplicatePackageCheckerPlugin, etc.):

Plugins such as BundleAnalyzerPlugin, DuplicatePackageCheckerPlugin, and CircularDependencyPlugin are conditionally added based on the environment. This is great for maintaining a clean and modular configuration.
Improvement Suggestion: Consider separating the configuration of these plugins into distinct functions. This would improve the separation of concerns and readability. For instance, a function like addPluginsForProduction(config) could be created to handle all plugin-related logic for the production environment.
Verbose Plugin Configurations in Non-CI Environments:

The BundleAnalyzerPlugin is configured to generate a report (report.html) when certain environment variables are set, like ANALYZER or CI.
No issues: This is a standard way to trigger analysis in non-CI environments, and the configuration is correctly gated behind environment variables.
Webpack Optimizations (usedExports):

The config.optimization.usedExports = true; setting is used to enable tree-shaking, reducing bundle size by removing unused exports.
No issues: This is an effective optimization to reduce the size of non-minified distribution files.
Direct Assignment of Webpack Config:

The final export assigns webpackConfig to the module exports using the spread operator: module.exports = [...webpackConfig];.
No issues: This is appropriate, especially if getWebpackConfig returns an array. Spreading ensures any array returned by getWebpackConfig is flattened, which can prevent unexpected behavior.

Signed-off-by: Akshit Bansal <[email protected]>
Copy link

stackblitz bot commented Oct 2, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Preview is ready

Copy link
Contributor

github-actions bot commented Oct 2, 2024

👁 Visual Regression Report for PR #51098 Passed ✅

🎯 Target branch: master (e8b0fc4)
📖 View Full Report ↗︎

🎊 Congrats! No visual-regression diff found.

Copy link

pkg-pr-new bot commented Oct 2, 2024

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e8b0fc4) to head (4faec8c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #51098   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          760       760           
  Lines        13491     13491           
  Branches      3504      3504           
=========================================
  Hits         13491     13491           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@afc163 afc163 changed the title Update webpack.config.js chore: Update webpack.config.js Oct 3, 2024
@afc163 afc163 merged commit 34cf399 into ant-design:master Oct 3, 2024
71 of 73 checks passed
@Wxh16144 Wxh16144 mentioned this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants