-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix tree shaking #415
Fix tree shaking #415
Conversation
console.warn( | ||
`[soramitsu-ui warn]: Invalid prop: type check failed for prop "${name}". Expected: ${formattedList}, got ${formattedValue}`, | ||
`[soramitsu-ui warn]: Invalid prop: type check failed for prop "${String( | ||
name, | ||
)}". Expected: ${formattedList}, got ${formattedValue}`, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
var could be a Symbol. TypeScript prevented runtime error!
|
||
"types": ["vitest/importMeta"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make in-source tests possible.
define: { | ||
'import.meta.vitest': 'undefined', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be useful when there some in-source tests appear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are new components, so it's necessary to make same operations to them
Changes
ui
library now has unit & after-build tests driven byvitest
For other details please see changesets.
Explorations
TypeScript
enum
s are evil. They are not tree-shakeable because they are compiled to IIFE:The way I used to work-around it:
jsoneditor
andlodash
(**edit:**not sure) are evil. They have side-effects. Fortunately, they are only used withinSJsonInput
. I excluded this component from the bundle temporarily - anyway it is unused and out of design system.body-scroll-lock
is evil too, but only a bit. It has a small side-effect check code. I think it can be implemented in pure manner, and maybe I'll open a PR. upd: The package is not tree-shakeable due to side-effects willmcpo/body-scroll-lock#254 and Fix tree shake by adding some/* @__PURE__ */
marks willmcpo/body-scroll-lock#255For now, I exclude it from
SModal
component, but I add a new component -SBodyScrollLockProvider
.SModal
will use it's locker by default. For details please see sources andSModal.spec.cy
for usage example (it usesbody-scroll-lock
small wrap).defineComponent()
should always be used with/* @__PURE__ */
or/* #__PURE__ */
prefix. Generally, it should be avoided.vite.config.ts
→build.target
set toesnext
. It produces more pure code, and in some cases it matters for tree-shaking.The exact case is the following:
SFC with 2
<script lang="ts">
blocks;Some component options:
As a result, without
esnext
target there is a dirt that prevents component to be tree-shaken.