Replies: 2 comments 3 replies
-
I do not think there is out of the box configuration you can control those behaviors at the moment, or in the future. There is actually some discussions around tree shaking controllability but that doesn't gaurantee anything if there'll be public interface or not. I can't comment around specified location yet, but I agree for now trying to modifying code paths in rust modules seems fastest workaround you can try. |
Beta Was this translation helpful? Give feedback.
-
If you are not going to use imported identifier, you can remove import specifier to indicate swc that it's an import for side-effects. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone!
Quick question. Is there any way to disable the tree-shaking the SWC bundler performs ??
Here is my use case. I'm trying to build a tiny JavaScript runtime using an engine that does not support es-modules, so my "big" idea for giving modules to the users was to use swc_bundler to bundle everything into a single script (no imports whatsoever) and then pass the generated file to the engine. That works fine until we hit the
REPL problem
.In the REPL I want to support imports as well:
Now the problem arises when I pass this line
import confetti from 'https://cdn.skypack.dev/canvas-confetti';
through the bundler. Since we're not using the import immediately the bundler sees it as an unused import (or something) and eliminates it from the final bundle returning just\n
as the output.So, on the rust side is there a way to disable the bundler's optimizations ??
I'm guessing this is where the optimization happens https://github.com/swc-project/swc/blob/main/crates/swc_bundler/src/bundler/optimize.rs (i might be wrong though 🤷♂️)
If there is no available solution at the moment, is adding another option inside the config a possibility ??
I know my use case is quite rare trying to make a bundler less performant 😅 , but is there any solution I'm currently missing ??
Thanks! 🙂
Beta Was this translation helpful? Give feedback.
All reactions