Thread
#multiplatform
    Hamza

    Hamza

    3 years ago
    How can I compile Kotlin-JavaScript to JavaScript files in a multiplatform project? There is only one gradle file
    gildor

    gildor

    3 years ago
    only one gradle file? what do you mean
    Hamza

    Hamza

    3 years ago
    like the new multiplatform version type
    not the one with a build gradle file for each module
    gildor

    gildor

    3 years ago
    so?
    Hamza

    Hamza

    3 years ago
    just giving more info…
    gildor

    gildor

    3 years ago
    you define js in
    targets
    , as I understand
    Hamza

    Hamza

    3 years ago
    doesn’t help too much. doesn’t show how to compile the kotlin source into javascript source
    gildor

    gildor

    3 years ago
    What is exactly problem? If you run task
    build
    , it will build code for all platforms and you will have .js file in output
    Hamza

    Hamza

    3 years ago
    oh.. 🤦‍♂️ . thanks
    one final question, how can i get gradle to generate the kotlin master stdlb file for me?
    gildor

    gildor

    3 years ago
    master stdlb? for JS?
    Hamza

    Hamza

    3 years ago
    yep
    gildor

    gildor

    3 years ago
    Not sure how this work with new MPP plugin, for js plugin it generates it automatically
    Hamza

    Hamza

    3 years ago
    yeah, it doesn’t do so with mpp
    gildor

    gildor

    3 years ago
    I also had this problem with one of my pet js projects
    don’t re member how I solved
    Hamza

    Hamza

    3 years ago
    is it on github?
    gildor

    gildor

    3 years ago
    Maybe just dpend on stdllib from dependencies
    Not sure, probably not
    Hamza

    Hamza

    3 years ago
    i meant is your project on github 😅
    gildor

    gildor

    3 years ago
    yes, I understand
    Hamza

    Hamza

    3 years ago
    okay. i have the kotlin-js stdlib in my jsmain as implementation but that didn’t compile it
    gildor

    gildor

    3 years ago
    No, I mean I used stdlib as npm dependency
    Hamza

    Hamza

    3 years ago
    oh, im using js as client with ktor as backend
    isn’t npm only for back end (server)?
    gildor

    gildor

    3 years ago
    no, if you use something like webpack to merge js files or any other way to work with dependencies for js
    Hamza

    Hamza

    3 years ago
    ok, ill check it out
    gildor

    gildor

    3 years ago
    For real project I anyway would use DCE instead of full stdlib
    actually maybe DCE generates stdlib 🤔
    honestly don’t remember
    Hamza

    Hamza

    3 years ago
    well im a noob at js, and i dunno what webpack is, so im learning everything
    gildor

    gildor

    3 years ago
    Hamza

    Hamza

    3 years ago
    kk, thanks
    gildor

    gildor

    3 years ago
    and with DCE you should get special stripped version of stdlib
    Hamza

    Hamza

    3 years ago
    and i should use dce with webpack, or is dce standalone?
    gildor

    gildor

    3 years ago
    standalone
    Hamza

    Hamza

    3 years ago
    looking into dce, isn’t it a plugin? How will i integrate it with the MPP application? my apologies, i am not very good at gradle :{
    Jurriaan Mous

    Jurriaan Mous

    3 years ago
    I use this extra code in the gradle script in the new multiplatform project structure to copy also all the dependencies and run the JS tests:
    task installMocha(type: NpmTask) {
        args = ['install', 'mocha']
    }
    
    afterEvaluate {
        // Directory for all js test dependencies
        def testDir = "${buildDir}/jsTest"
        def projectName = name
    
        // Copy test files
        task copyJsTestOutput(type: Copy, dependsOn: [compileTestKotlinJs]) {
            from compileTestKotlinJs.outputFile.parentFile.path
            include "*.js"
            include "*.js.map"
            into testDir
        }
    
        // Copy all to be tested code and dependencies
        task copyJsMainOutputAndDependencies(type: Copy, dependsOn: compileKotlinJs) {
            from compileKotlinJs.destinationDir
            configurations.jsTestCompileClasspath.each {
                from(zipTree(it.absolutePath).matching { include '*.js.map'; include '*.js' })
            }
    
            into("${testDir}/node_modules")
        }
    
        // Use mocha as the test runner
        task runMocha(type: NodeTask, dependsOn: [copyJsMainOutputAndDependencies, copyJsTestOutput, installMocha]) {
            script = file('node_modules/mocha/bin/mocha')
            args = ["${testDir}/${projectName}_test.js"]
        }
    
        // Let mocha run when test is run in JS target
        jsTest.dependsOn runMocha
    }
    Hamza

    Hamza

    3 years ago
    Thanks. I will give this a shot