I'm not sure how `Webpack` work in `Kobweb` or eve...
# kobweb
a
I'm not sure how
Webpack
work in
Kobweb
or even
Kotlin/JS
But when using libraries, it's better to install them using
npm
package manager and import only the things you need from the package/library to reduce the production bundle size and make the app faster, I tried
Webpack
in
Vanilla JS
projects and in
React/Next js
but I'm not how it work in
Kotlin/JS
target, I see most
Kotlin
developers import the full css and js using public CDN instead of using
npm
and import something only the things you need, but why? does this method have any downsides that doesn't exist on normal JS projects?
c
What you're showing in this screenshot isn't "importing from a public CDN", it's the Kotlin syntax equivalent of
Copy code
import './@material/web/button/test-button.js'
In JS, this would be an import at the top of the file. But Kotlin only allows importing Kotlin files, so if you want to import a JS or CSS file, you use this function instead. (now, I don't know this project, so maybe the
require
function is different there)
But to answer your question, no, the tradeoffs behind using a CDN or not are the exact same in JS and in Kotlin/JS.
(another reason you didn't mention: using a CDN is not compatible with GDPR in the EU, because it allows the CDN to track your users)
👍 1