Hey guys, Wanted to ask a quick question if someon...
# javascript
m
Hey guys, Wanted to ask a quick question if someone faced the same issue. I want to have JS target for NodeJS and another one for browser and I want in both to use
fetch
instead of
XMLHttpRequest
Is there is a documentation for that part in KMM documentation or a workaround that you know of?
a
you can build for both browser and nodejs in one target. Must you separate them?
m
using two different
JS
targets But if I had to choose between one of them I would choose the NodeJS
Copy code
kotlin {
    js(LEGACY) {
        this.binaries.executable()
        this.useCommonJs()
        browser {
            webpackTask {
                this.output.libraryTarget = "var"
            }
            commonWebpackConfig {
                this.cssSupport.enabled = true
            }
            testTask {
                useKarma {
                    useChromeHeadless()
                }
            }
            distribution {
                this.directory = File("$projectDir/build/browser")
            }
        }
    }
    js("nodeJS", IR) {
        this.binaries.library()
        this.useCommonJs()
        nodejs {
            distribution {
                this.directory = File("$projectDir/build/nodejs")
            }
        }
    }
}
a
Copy code
How about??

kotlin {
  JS(IR) {
    browser()
    nodejs()
  }
}
m
I will try it out