hi, is there a way to include handwritten js files...
# javascript
a
hi, is there a way to include handwritten js files into a kotlin/js project? To make them part of the webpack bundle? I tried to set the "entry" property in (common)WebpackConfig but it didn't help.
t
Do you want to use it in Kotlin/JS or it’s standalone script?
a
the other way around. I want to use the kotlin/js generated code from it.
t
V1. You can add it in
src/main/resources
. Kotlin/JS will copy it in webpack build dir V2. You can copy script in webpack build dir via
processResources
task
a
Thanks for the suggestions, for V1: that one I have tried as well and that does copy the file over "as is" but I would like the js file to be part of the webpack bundle. I will try V2.
apparently I got what I wanted using the V1 suggestion + a bit of a workaround, as I had to create a kotlin file to "depend" on my js file:
Copy code
@JsModule("./myfoobar.js")
@JsNonModule
external fun foo()
Note that foo() doesn't exist in my myfoobar.js, I only need it to have a place to add the annotations (using file annotations doesn't work). Now myfoobar.js gets included into the webpack bundle. Thanks for the help.
t
Do you want to change entry instead?
a
if by that you mean changing the entry of webpack... when I did that it effectively overwrote the default kotlinjs entry and so the default kotlin bundle was not included anymore. I think currently we are not supposed to change the entry.
t
Entry can be changed by webpack patch
You can add additional or replace existed
a
So that works as well, adding a js file with this:
Copy code
config.entry.main.push("./../../../../src/main/js/mybar.js")
into the webpack.config.d folder