Closed zOadT closed 1 year ago
Thanks! Currently testbed has side effect (it reimplement Testbed.mount from main package), would that be a problem now, or if we want to split testbed implementation into its own build?
Thanks! Currently testbed has side effect (it reimplement Testbed.mount from main package), would that be a problem now, or if we want to split testbed implementation into its own build?
Ah ok thanks, didn't know about that in testbed. Then we have to provide a glob of modules with side-effects (see last code example of this section)
I guess probably something like
"sideEffects": ["./dist/*-with-testbed.*"],
should work, but I have to test it if it really works with the exports
field in package.json.
The glob worked! In the above example Planck still won't be bundled, in this example it still got included in the bundle: (tested with webpack and vite)
import { Vec2 } from "planck/with-testbed";
if (false) {
console.log(Vec2)
}
Cool, thanks! It would great if you add some instructions, or a repo with sample project, to test it (in case someone wants to change it they know how to test it).
Cool, thanks! It would great if you add some instructions, or a repo with sample project, to test it (in case someone wants to change it they know how to test it).
Good point! I don't really have any fancy setup, but I added a short section about how to test it.
This PR sets
sideEffects
to false to improve the builds for the users.What does it do?
Some informations can be found here. In our case it will only prevent Planck from being included in the bundle if its not used (and maybe some other minor optimisations from the bundler)
So yes, pretty minor thing, but also only a pretty minor change. I am currently indeed actively overriding this setting to
false
in a webpack config.Is it Webpack specific?
No, even though most of the documentation you see online is for Webpack, also tools like Vite are using it.
How to test it?
You can test the change by making a simple build setup:
Create a file
src/index.js
with the code given above (you can also use.ts
for vite. For webpack you would have to add a webpack config to configure ts-loader). To test vite you also have to create aindex.html
at the root that includes this script tag:<script src="src/index.js" type="module"></script>
. Then runor
and check the generated js file in the
dist
folder.You can edit
node_modules/planck/package.json
directly to see how it changes the generated code.