How to shim modules using alias? #2413
Unanswered
jonrimmer
asked this question in
Troubleshooting
Replies: 2 comments
-
So, the problem turned out to be that esinstall filters out any alias with an absolute mapping. This is a bug, because it prevents you from aliasing modules in dependencies. I'll submit a PR to fix this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Also stumbled on this. Requires running npm install between each change in the shim. |
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
-
I'm finding it impossible to use alias to shim modules. It just doesn't seem to work as indicated in the docs.
Our project has Chart.js as a dependency. For backwards-compatibility reasons, Chart.js v2 has Moment.js as a dependency, but doesn't strictly require it, as it can use another library, like Luxon, if configured properly. However, since it still imports Moment, it can end up bloating your bundle size. The solution is to shim Moment with an empty module.
However, when I try to configure this with Snowpack, it doesn't seem to work. This is what I have in my
snowpack.config.js
:And the
./shims/moment
directory contains apackage.json
and anindex.js
with an empty default export.As far as I can tell, this should be enough to replace the "real" Moment.js with the shim, but it doesn't work. When I start the Snowpack, the Chart.js dependency it still creates the Chart.js dependency in the package cache with the full Moment.js module inlined inside it.
Am I missing something obvious?
I have a repro project here: https://github.com/jonrimmer/snowpack-test
Beta Was this translation helpful? Give feedback.
All reactions