TreeShaking #805
IWANABETHATGUY
started this conversation in
RFC
TreeShaking
#805
Replies: 1 comment
-
Esbuild one level lookupindex.mjs import { a, c } from "./test.mjs";
export function test() {
c;
} test.mjs function a() {}
export { a, c };
function c() {
class Test {
a() {
a();
}
}
}
// export default 20; Output
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Tracking issue of <Fill in the RFC title above>
Summary
Motivation
Support rspack tree-shaking
Guide-level explanation
index.js
result.js
test.js
生成一个 symbol graph
index.js
result.js
tes.js
with side effects
index.js
result.js
test.js
Rationale and alternatives
SWC resolver
After the swc resolver analysis we have a syntaxContext on each binding
identifier
.Create a Symbol graph, and if there is a reference to another binding in any of the declarations, create an edge to that symbol
Iterate through all reachable symbols from the root of the graph, and mark all unreachable symbols as unused and wait for
DCE
to delete them.Side Effect positive and negative propagation
Prior art
Webpack
Collection Module Export
Convert named exports to
HarmonyExportSpecifierDependency
objectsConvert
default
exports toHarmonyExportExpressionDependency
objectsMount all exported information on ModuleGraph
Mark the module for export use (only variables used directly by the module are recorded, information about indirect references is lost)
index.js
test.js
webpack.config.js
output
esbuild output
usedExports
innerGraph (deep-scope-analysis)
Resolve issue like Unexpected code after tree-shake webpack/webpack#6264
concatenateModules (scope hoisting)
provideExports
export * from 'xxx'
Progressive Implementation
Mark all
esm
exports, count unused exports (without side effects tracking)export xxx
and export defaultreexport
namespace member accesses
side effect tracking
module level side effects
dynamic importcommonJs
pure annotations
None es module tree shaking (css)
Beta Was this translation helpful? Give feedback.
All reactions