Anyone who could help ? I have an issue with tests...
# javascript
j
Anyone who could help ? I have an issue with tests, because of missing external dependency... I do have simple hello world app with external js dependency, the code works fine in a browser. But not sure how to tell gradle to include my external js when running my tests.
r
cc: @Ilya Goncharov [JB]
t
Could your show your build script?
j
@turansky
Copy code
plugins {
    id 'org.jetbrains.kotlin.js' version '1.3.60'
}

group 'com.test.kotlinjs'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-js"
    testImplementation "org.jetbrains.kotlin:kotlin-test-js"
}

kotlin.target.browser { }
I have just this ^, based on intellij's gradle/kotlinjs template...
Also I'm not totally sure how to build an artifact... currently
./gradlew assemble
will create my js + kotlin.js somewhere in the build folder, but I have a feeling there should be a better way of doing it...
i
You can run task
browserWebpack
to build bundle via webpack, which is ready to run in browser, and you can use
browserRun
to run it with hot reload For testing in browser, you need to bundle all your dependencies in one js. By default gradle plugin do it for you (via webpack), but you need to declare javascript dependencies in gradle script Another option, if it is plain js in your project (in resources for example), you need to say for webpack, where it should find your js If you can share your project, it will simply to explain But in common words, you can create
webpack.conf.d
folder and create plain js for configuring webpack For example you can use
alias
(https://webpack.js.org/configuration/resolve/#resolvealias) Something like (relative path should be relative with base
build/js/packages/<your-module-name>
Copy code
;(function () {
    const path = require('path');
    config.resolve = config.resolve || {};
    config.resolve.alias = {
        dependency: path.resolve(__dirname, 'path/to/dependency.js')
    };
}());
j
so is it going to the
webpack.conf.d
? I was trying to figure out how to tell gradle in
dependencies
is there a doc or thread here in slack at least little bit about the gradle plugin configuration/tasks etc ? It's really hard even start 😕
i
Documentation now is in process, stay tuned 🙂 You can find something useful in release blog post 1.3.40, where this was added https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/ Now we work on declaring npm dependencies in root
dependencies
block of gradle script
j
thanks a lot 👍