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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: asset resource side effects #2849

Merged
merged 18 commits into from
Apr 27, 2023
Merged

Conversation

IWANABETHATGUY
Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY commented Apr 20, 2023

Related issue (if exists)

Closed #2804

Summary

馃 Generated by Copilot at 070e0b3

This pull request implements and improves the tree-shaking optimization for rspack_core and rspack_plugin_javascript crates, using a new OptimizeAnalyzer trait and a new OptimizeAnalyzeResult struct. It also adds a new sideEffects option to the compiler and the rspack.config.js file, to enable or disable the optimization based on the module metadata. It also adds an example project that demonstrates the usage of asset modules and the tree-shaking optimization.

Walkthrough

馃 Generated by Copilot at 070e0b3

  • Rename TreeShakingResult to OptimizeAnalyzeResult and update imports and types accordingly (link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Add include_module_ids field to Compilation struct and populate it with the result of tree-shaking optimization (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Remove used flag from ModuleGraphModule struct and related logic, since it is no longer used for tree-shaking (link,link,link,link,link)
  • Rename SideEffect enum to SideEffectType and update imports and pattern matching accordingly (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Add OptimizeAnalyzer trait and implement it for JsModule and AssetModule structs, to provide a common interface for analyzing different types of modules for tree-shaking optimization (link,link,link,link,link)
  • Rename ModuleGraphModule struct to ModuleType and derive it with Default, to avoid confusion with the ModuleGraphModule struct in the module_graph module and allow creating an empty instance (link)
  • Add included_in_chunk method to ModuleType struct, to check if a module should be included in the final chunk based on the include_module_ids set and the side_effects_options flag (link,link)
  • Move ConvertModulePath trait from mod.rs to utils.rs, to avoid circular imports (link,link,link)
  • Add ExtraMark struct to pass the marks for the top-level and helper symbols to the tree-shaker (link,link,link,link,link,link,link)
  • Move tree_shaking.rs file from rspack_plugin_javascript crate to rspack_core crate, to make the tree-shaking logic more generic and reusable for different types of modules (link)
  • Add options parameter to tree_shaking function and TreeShaker struct, to pass the compiler options to the tree-shaker (link,link,link,link)
  • Change visibility of from_description method of SideEffects struct to pub, to allow using it from other modules (link)
  • Add index.js and package.json files to examples/basic/a folder, to demonstrate the usage of an asset module and the tree-shaking optimization (link,link)
  • Update rspack.config.js file to enable sideEffects and treeShaking options, set mode to development, and specify the type of asset modules (link)

@changeset-bot
Copy link

changeset-bot bot commented Apr 20, 2023

鈿狅笍 No Changeset found

Latest commit: ba909a2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Apr 20, 2023
@IWANABETHATGUY IWANABETHATGUY changed the title Feat/asset resource side effects feat: asset resource side effects Apr 20, 2023
@IWANABETHATGUY IWANABETHATGUY force-pushed the feat/asset-resource-side-effects branch 2 times, most recently from 750fc3c to 7223674 Compare April 26, 2023 12:06
@IWANABETHATGUY IWANABETHATGUY force-pushed the feat/asset-resource-side-effects branch 2 times, most recently from 0c3449f to c367be8 Compare April 26, 2023 13:06
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review April 27, 2023 04:44
@IWANABETHATGUY IWANABETHATGUY force-pushed the feat/asset-resource-side-effects branch from c367be8 to fc7e40a Compare April 27, 2023 04:44
@IWANABETHATGUY IWANABETHATGUY force-pushed the feat/asset-resource-side-effects branch from fc7e40a to 08d0a1c Compare April 27, 2023 07:39
@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Apr 27, 2023
Merged via the queue into main with commit f297df4 Apr 27, 2023
10 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the feat/asset-resource-side-effects branch April 27, 2023 08:07
siyou pushed a commit to siyou/rspack that referenced this pull request May 14, 2023
* chore: 馃 ck point

* chore: 馃 init include_module_ids

* chore: 馃 update test

* chore: 馃 update test

* chore: 馃 make test pass

* chore: 馃 update used ids

* feat: update include_module_ids strategy

* feat: more abstraction

* feat: 馃幐 add asset module

* chore: 馃 inspect asset module side effects

* chore: 馃 recover main bindinng.d.ts

* chore: 馃 clean up

* chore: 馃 finish it

* chore: 馃 add test

* chore: 馃 pass test

* chore: 馃 clean up

* chore: 馃 lint

* fix: 馃悰 cr issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sideEffects should apply to static assets.
2 participants