https://kotlinlang.org logo
#javascript
Title
# javascript
l

Lukas S

08/01/2022, 8:48 AM
Hi, I'm trying to create a full stack website with Kotlin/JS and Kotlin/JVM. I would like to create 1 js file for each page that I have on my website, however when building the project it merges all of the files into one js script. I was wondering if there was any way I could change that? I know that if you create submodules, it will compile 1 js file for each module, however I don't feel like this is a good solution as I would have to create one module for each page Thanks
b

Big Chungus

08/01/2022, 9:02 AM
Not possible at the moment
t

turansky

08/01/2022, 9:05 AM
a

Alex Buznik

08/01/2022, 10:54 AM
Actually, you can configure webpack to have multiple entrypoints, so every page could import its own JS file. It's a bit tricky, but a pretty standard way of doing things. You can start here: https://webpack.js.org/concepts/output/
Another way to do it would be to use a client-side router, so you could still to use one exported js file, but use different code from it depending on the current page.
b

Big Chungus

08/01/2022, 11:33 AM
Since kjs does not support es6, I'm not sure how webpack would split your bundle
a

Alex Buznik

08/01/2022, 12:45 PM
@Big Chungus, how is it a question of es6? You can create multiple source entrypoint files, that only import what they need
b

Big Chungus

08/01/2022, 1:43 PM
No es6 -> no tree shaking, so you would be shipping an entire bundle for each page (even in the entry point is different). At that point you're better off going with a SPA
l

Lukas S

08/02/2022, 6:29 PM
Thanks for the replies, i've tried to configure multiple entry points with webpack as Alex suggested however the only output files are .kjsm, and with webpack you need to use .js files for entry points, so I don't think its possible atm (unless anyone has any other ideas?) I feel like this holds kotlin/js back from being used as a viable solution for full stack web development
b

Big Chungus

08/02/2022, 6:48 PM
To get js outputs use binaries.library() or binaries.executable() To configure webpack use webpack.config.d folder (search around that)
7 Views