Git Product home page Git Product logo

kotlin-frontend-plugin's Introduction

kotlin-frontend-plugin Download TeamCity (simple build status)

THIS PLUGIN IS DEPRECATED

Kotlin/JS plugin contains features of kotlin-frontend-plugin.
For setting up project with Kotlin/JS Gradle Plugin, please follow
https://kotlinlang.org/docs/reference/js-project-setup.html


Gradle plugin for Kotlin frontend development

The plugin provides an easy way to gather Maven and npm dependencies, pack bundles (via webpack) and test a frontend application using Karma. By default the plugin generates all required configs for webpack, karma and manages the corresponding daemons.

By using Gradle continuous build, you also can get hot module replacement feature (apply code changes in browser on the fly). See corresponding section below.

Howto

Configure Gradle project

First of all you have to apply plugin org.jetbrains.kotlin.frontend and setup Kotlin:

buildscript {
    ext.kotlin_version = '1.3.21'

    repositories {
        jcenter()
        maven {
            url "https://dl.bintray.com/kotlin/kotlin-eap"
        }
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.45"
    }
}


// apply plugin
apply plugin: 'org.jetbrains.kotlin.frontend'

// apply kotlin2js
apply plugin: 'kotlin2js'

// configure kotlin compiler
compileKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
    kotlinOptions.sourceMap = true
    kotlinOptions.moduleKind = 'commonjs'
    kotlinOptions.main = "call"
}

Setup npm dependencies

All frontend plugin settings are applied in kotlinFrontend section:

kotlinFrontend {
    npm {
        dependency "style-loader" // production dependency
        devDependency "karma"     // development dependency
    }
}

webpack bundler

To create a webpack bundle (for both packaging and running the dev server):

kotlinFrontend {
    webpackBundle {
        bundleName = "main"
    }
}

Complete example

See examples/frontend-only/build.gradle for a full example.

Building and running

To run dev server (that also will build kotlin sources):

gradlew run

To run tests:

  • run gradlew tests to build the tests and start the Karma daemon
  • open http://localhost:9876 to run the tests in your browser using Karma

To pack the bundle:

gradle bundle

To stop running webpack and Karma daemons:

gradle stop

webpack

webpack configuration:

kotlinFrontend {
    webpackBundle {
        bundleName = "main"
        sourceMapEnabled = true | false   // enable/disable source maps 
        contentPath = file(...) // a file that represents a directory to be served by dev server)
        publicPath = "/"  // web prefix
        host = "localhost" // dev server host
        port = 8088   // dev server port
        proxyUrl = "" | "http://...."  // URL to be proxied, useful to proxy backend webserver
        stats = "errors-only"  // log level
    }
}

dev server log is located at build/logs/webpack-dev-server.log

config file is generated at build/webpack.config.js

webpack configuration customization

To customize webpack configuration, you can apply additional scripts by placing them in the directory webpack.config.d. The scripts will be appended to the end of config script. Use number prefix to change order (it is very similar to UNIX rc.d config directories)

Sample structure:

  • [DIR] webpack.config.d
    • css.js
    • minify.js
    • 10-apply-ealier.js
    • 20-apply-later.js

Karma

Karma configuration:

kotlinFrontend {
    karma {
        port = 9876
        runnerPort = 9100
        reporters = listOf("progress") 
        frameworks = listOf("qunit") // for now only qunit works as intended
        preprocessors = listOf("...")
    }
}

This will generate a config file located at build/karma.conf.js.

Note that for your tests to run correctly with webpack their module type must be defined as well:

compileTestKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.moduleKind = 'commonjs'
}

If you would like to use a custom karma.config.js then specify it using customConfigFile:

kotlinFrontend {
    karma {
        customConfigFile = "myKarma.conf.js"
    }
}

Your custom config file will be copied to the build folder and renamed to karma.config.js.

karma log is located at build/logs/karma.log

Hot module replacement

Webpack provides ability to apply code changes on the fly with no page reload (if possible). For reference see Webpack Hot Module Replacement documentation

Webpack does a lot of work for you however to get it working well most likely you have to implement state save and restore functionality via webpack's API. See HMR.kt for corresponding Kotlin external declarations for webpack API and main.kt for sample save/load.

Briefly at module load accept HMR feature and listen for disposal

module.hot?.let { hot ->
    hot.accept() // accept hot reload
    
    hot.dispose { data -> // listen for disposal events
        data.my-fields = [your application state] // put your state in the 'data' object
    }
}

To get previously saved state at module load use module.hot?.data

    module.hot?.data?.let { data -> // if we have previous state then we are in the middle of HMR
        myRestoreFunction(data) // so get state from the 'data' object
    }

Finally use Gradle continuous build with run task to get live replacement every time you change your code.

gradlew -t run

kotlin-frontend-plugin's People

Contributors

abendt avatar coyotesqrl avatar cy6ergn0m avatar drewcarlson avatar foso avatar garrisond avatar gbaldeck avatar ilgonmic avatar jakewharton avatar jonnyzzz avatar kapot65 avatar mulholo avatar orangy avatar romanart avatar snrostov avatar vkhikhlov avatar wem avatar winterbe avatar wiyarmir avatar yole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlin-frontend-plugin's Issues

Module not found: Error: Can't resolve 'kotlin' with Kotlin 1.2.40

After upgrade to Kotlin 1.2.40 there is an error building any project using kotlin-frontend-plugin. Sample log from frontend-only example looks like this:

ERROR in ./frontend-only.js
Module not found: Error: Can't resolve 'kotlin' in '/home/rjaros/git/github/kotlin-frontend-plugin/examples/frontend-only/build/js'
@ ./frontend-only.js 254:18-35

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':webpack-bundle'.
    node webpack.js failed (exit code = 2)

Builds don't fail when karma test fails

By adding a assertTrue(false) in TestLinesPresenter in the frontend-only example project, I expected the gradle build to fail. However, gradle exits with "BUILD SUCCESSFUL" even though a test failed. The test failure can be seen at http://localhost:9876/.

I can work around this by adding the following to the build.gradle:

task karmaRun(type: Exec) {
    workingDir 'build'
    commandLine 'node_modules/karma/bin/karma', 'run'
    dependsOn compileTestKotlin2Js
}

test.dependsOn karmaRun

Can't make the proxy work

Hi,

I'm playing with the kotlin frontend plugin. I have a backend (running on port 9090) and a frontend (running on port 9091). My frontend module uses the kotlin frontend plugin with the following config:

kotlinFrontend {
    downloadNodeJsVersion = 'latest'

    npm {
        dependency "react"
        dependency "react-dom"
    }

    webpackBundle {
        publicPath = "/frontend/"
        port = 9091
        proxyUrl = "http://localhost:9090"
    }
}

When I run the frontend module, I can see my js file loading fine at the url http://localhost:9091/frontend/frontend.bundle.js but not on the url http://localhost:9090/frontend/frontend.bundle.js which I assumed it should be proxyed to.
Is there anything I'm doing wrong?

Is the order of the files in the `*. config.d` directory incorrect?

The following description is in usage:

- 10-apply-ealier.js
- 20-apply-later.js

I created files and tried it as follows:

webpack.config.d
    10-config-20.js
    20-config-10.js

In the generated webpack.config.js, it is written as follows:

// from file .../webpack.config.d/20-config-10.js
{
   "name": "20-config-10"
}
// from file .../webpack.config.d/10-config-20.js
{
   "name": "10-config-20"
}

Is the order incorrect? The order is not decided by prefix.

I am sorry if it is a misunderstanding. If the order is incorrect, I think that if we correct the following code it will be fixed.

Local Maven Repo for dependencies

I'm trying to use an artifact stored in my local maven repository as a dependency for another project, like so (build.gradle file):

...
repositories {
    mavenCentral()
    mavenLocal()"
 }

 dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    compile "mygroup:myartifact:1.0.0-SNAPSHOT" <- the local dependency
    testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
 }
...

this seems to work alright the dependency is unpacked into node_modules_imported in the build directory as it is supposed to (I guess).

But, now, the package.json located under build/resources/main states this:

{
    ...
    "dependencies": {
        "myartifact": "file:///home/user/.m2/repository/mygroup/myartifact/1.0.0-SNAPSHOT/myartifact- 1.0.0-SNAPSHOT.jar",
        "kotlin": "file:///home/user/Project/build/node_modules_imported/kotlin/"
         ...
    },
   ...
}

which wouldn't work and seems wrong as opposed to what it says for the kotlin dependency.

Am I doing something wrong, is it not supposed to work like that or what is the deal here?

add Gradle Script Kotlin examples

Copy-pasting Gradle/groovy examples to Gradle/kts does not seem to work clearly. It might be nice to have a .kts examples too for those who decided to use Gradle Script Kotlin.

Deprected gradle feature used

When running a build using the frontend pugin with gradle 4.7, the following message appears:

The TaskInternal.execute() method has been deprecated and is scheduled to be removed in Gradle 5.0. There are better ways to re-use task logic, see https://docs.gradle.org/4.7/userguide/custom_tasks.html#sec:reusing_task_logic.

Would be nice to have this fixed, also to look forward to gradle 5.

Support adding to karma files

It'd be great if there was support for adding additional karma files.

Something like:

karma {
  files = [pattern: "resources/main/tzdata-latest/**", watched: false, served: true, included: false]
}

This could be achieved by concatenating here:

"files" to listOf<String>(
kotlinTestOutput(project).absolutePath
),

This would enable workflows where the code being tested needs access to external resources.

How get access to kotlin module form js ?

Hello.

I have kotlin module "my_module" with code:

@JsName("myKotlinFunction")
fun myKotlinFunction() { 
        println("It is my kotlin function")
}

Without kotlin-frontend-plugin I can get access to "kotlin code" from js using module name like:

my_module.myKotlinFunction();

But it is not work when I use kotlin-frontend-plugin ...
Can you help please ?

Thanks.

kotlin.js

"Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to [module-js]"

This is a new error I'm receiving after trying to add a multi-platform project dependency to my app. Shouldn't the frontend plugin be bundling the kotlin runtime with my app code when I run ./gradlew -t run or ./gradlew build? It looks like this check is hard coded into the module-js?

Cannot find map even though it was generated

In project:

https://github.com/MarcinMoskala/KotlinAcademyApp

I got:

webpack-internal:///146:145 [WDS] Warnings while compiling.
msgWarnings @ webpack-internal:///146:145
webpack-internal:///146:148 /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules/kotlin.js
(Emitted value instead of an instance of Error) Cannot find SourceMap 'kotlin.js.map': Error: Can't resolve './kotlin.js.map' in '/home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules'
 @ /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/classes/kotlin/main/common-client-js.js 1171:18-35
 @ ./js/web.js
 @ multi webpack-dev-server/client?http://localhost:8088/ webpack/hot/dev-server ./web
msgWarnings @ webpack-internal:///146:148
webpack-internal:///146:148 /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules/kotlinx-coroutines-core-js.js
(Emitted value instead of an instance of Error) Cannot find SourceMap 'kotlinx-coroutines-core-js.js.map': Error: Can't resolve './kotlinx-coroutines-core-js.js.map' in '/home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules'
 @ /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/classes/kotlin/main/common-client-js.js 1171:37-74
 @ ./js/web.js
 @ multi webpack-dev-server/client?http://localhost:8088/ webpack/hot/dev-server ./web
msgWarnings @ webpack-internal:///146:148
webpack-internal:///146:148 /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules/common-js.js
(Emitted value instead of an instance of Error) Cannot find SourceMap 'common-js.js.map': Error: Can't resolve './common-js.js.map' in '/home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules'
 @ /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/classes/kotlin/main/common-client-js.js 1171:76-96
 @ ./js/web.js
 @ multi webpack-dev-server/client?http://localhost:8088/ webpack/hot/dev-server ./web
msgWarnings @ webpack-internal:///146:148
webpack-internal:///146:148 /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules/kotlinx-serialization-runtime-js.js
(Emitted value instead of an instance of Error) Cannot find SourceMap 'kotlinx-serialization-runtime-js.js.map': Error: Can't resolve './kotlinx-serialization-runtime-js.js.map' in '/home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/node_modules'
 @ /home/marcin/IdeaProjects/KotlinAcademyApp/common-client-js/build/classes/kotlin/main/common-client-js.js 1171:98-141
 @ ./js/web.js
 @ multi webpack-dev-server/client?http://localhost:8088/ webpack/hot/dev-server ./web

All these maps are generated and they can be found in node_modules_imported:

selection_023

Does not seem to bundle dependencies with default (blank) js moduleKind

When I tried to run the build with compileKotlin2Js.kotlinOptions.moduleKind undefined, the bundle does not seem to contain either kotlin standard libraries or other dependencies. Changing it to commonjs solved problem.

Disclaimer: I am completely unfamiliar with JS ecosystem and I still do not really understand how its module system works.

Exception while relativizing source map

OS: Windows 10
Java info:

java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

Kotlin version: 1.1.2-4 ( Also tried 1.1.2 and 1.1.4-dev-530 )
Plugin version: 0.0.19

Source map, that was generated using kotlin2js uses file://PATH_HERE ( for example file://F:/ ) URI's . While this is perfectly fine for windows, java doesn't like that and crashesh with exception.
Stack trace:

Caused by: java.lang.IllegalArgumentException: URI has an authority component
        at org.jetbrains.kotlin.gradle.frontend.SourceMapsKt.relativizeSourceMap(SourceMaps.kt:53)
        at org.jetbrains.kotlin.gradle.frontend.SourceMapsKt.relativizeSourceMap$default(SourceMaps.kt:36)
        at org.jetbrains.kotlin.gradle.frontend.RelativizeSourceMapTask.relativize(SourceMaps.kt:30)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
        ... 70 more

Error is here: https://github.com/Kotlin/kotlin-frontend-plugin/blob/master/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/SourceMaps.kt#L53

Some explanation:
First of all, any windows based path, that have disk name, will have :/. Because of that, check at line 52 will not work as intended with normal path.
And second reason, why it fails, is because java sees F: as authority ( aka domain ), and not as part of path.
This might be an error in kotlin2js, but I don't know. File("F:\").toURI() gives file:/F/ , witch is perfectly fine for java, but not windows.

For now, I just added doLast to compileKotlin2Js that replaces file:\\ with file:\\\

Allow type safe configuration of WebPackExtension

Hi,

I'm using the FrontendPlugin with Kotlin-Gradle-DSL.
But when configuring the WebPack-Bundle, I have to do the following:

configure<KotlinFrontendExtension> {
...
    bundle<WebPackExtension>("webpack") {
        if (this is WebPackExtension) { // -> "Workaround" to be typesafe
            bundleName = "main"
        }
    }
...
}

So if (this is WebPackExtension) { is needed to configure the WebPackExtension. Without that, the scope just would be BundleConfig because of the org.jetbrains.kotlin.gradle.frontend.KotlinFrontendExtension:

    fun <C : BundleConfig> bundle(id: String, configure: BundleConfig.() -> Unit) {
        bundleBuilders += Pair(id, configure)
    }

There the requested function type is not of type C but of type BundleConfig. I though understand why this is the case, but it is really annoying. Can this be improved?

Karma startup failed

Hi,
I've tried to run example frontend only on travis.
However I got karma startup error.
I randomly got similar error on my mac too.
I have no idea what can be cause of such behavior.
Thanks in advance
Karol

:karma-start
karma: not actually running so has been killed
webpack: wait until bundle finished: 
 FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':karma-start'.
> karma startup failed

https://travis-ci.org/elpassion/todo-kotlin-react-example/builds/219248535

./gradlew run on full-stack-example project fails

I get this:

➜  frontend-test ./gradlew run     
:frontend:npm-preunpack UP-TO-DATE
:frontend:npm-configure UP-TO-DATE
:frontend:npm-install
npm ERR! registry error parsing json
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/7.4.0/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5

npm ERR! Unexpected token < in JSON at position 0
npm ERR! <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
npm ERR! <html><head>
npm ERR! <title>403 Forbidden</title>
npm ERR! </head><body>
npm ERR! <h1>Forbidden</h1>
npm ERR! <p>You don't have permission to access /style-loader
npm ERR! on this server.</p>
npm ERR! </body></html>
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Y9CKMY/dev/other/kotlin/frontend-test/frontend/build/npm-debug.log
:frontend:npm-install FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':frontend:npm-install'.
> npm install failed (exit code = 1)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.412 secs

I figured out that any dependency I add in my build.gradle will cause this error (You don't have permission to access MODULE on this server)

In my case it is style-loader:

kotlinFrontend {
    npm {
        dependency("style-loader")

        devDependency("karma")
    }
}

webpack (full-stack-example) does not run

➜ full-stack-example git:(master) ✗ ./gradlew frontend:webpack-run\

Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

Configure project :frontend
Source map generation is not enabled for kotlin task compileTestKotlin2Js

Task :frontend:webpack-run FAILED
webpack-dev-server exited with exit code 1, see /Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/full-stack-example/frontend/build/logs/webpack-dev-server.log
module.js:557
throw err;
^

Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object. (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/full-stack-example/frontend/build/webpack-dev-server-run.js:5:15)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)

npm configuration names recognize minus operator and do not work as intended.

Hello!

I was beginning to use this plugin in my project, and I wanted to configure the npm task so I could possibly have it install to a separate directory.

Currently, it installs to $PROJECT_DIR$/build/npm-modules which is a huge issue for me because I frequently run the clean task before compiling and building my project, which deletes the entire /npm-modules directory and requires a reinstall.

Regardless whether or not this is possible to do, I checked to see if there was a way to configure npm and found npm-configure. However, it appears this task recognizes the - operator before recognizing the full name of the configuration.

source maps

Hello,
I am testing the frontend plugin and configured it (similar to the examples) to generate source maps.
I can see the source maps (kjsm files I assume) generated under the build/js library
but on the browser there seem to be no source maps present - are there some settings I am missing?

How to contribute

Hi,

How can I contribute to the project? Is there any guidelines?

build.gradle.kts: Unresolved reference: compile

Gradle 4.2.1

build.gradle.kts:

import org.jetbrains.kotlin.gradle.frontend.FrontendPlugin

buildscript {
    val kotlinVersion = "1.2-M2"

    repositories {
        jcenter()
        maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
        maven(url = "https://dl.bintray.com/kotlin/kotlin-dev")
    }
    dependencies {
        classpath(kotlin("gradle-plugin", kotlinVersion))
        classpath(kotlin("frontend-plugin", "latest.release"))
    }
}

apply {
    plugin("kotlin2js")
}
plugins.apply(FrontendPlugin::class.java)

repositories {
        jcenter()
        maven(url = "https://dl.bintray.com/kotlin/kotlin-dev")
}

val kotlinVersion = "1.2-M2"

dependencies {
    compile(kotlin("stdlib-js", kotlinVersion))
}

Cannot find module 'qunit'

I was trying to run the tests in a project I was starting, but they were failing with

Cannot find module 'qunit'

I assumed I must be doing something wrong, so I tried the example project and got the same result.

Does the plugin assume qunit is already installed somewhere on the development machine? The readme doesn't mention qunit outside of the karma configuration. The frontend-only example doesn't even have that. It's not clear if this is a bug in the plugin or lack of proper documentation/up-to-date example projects.

Output from running from the example directory in a clean checkout of the repository at e8aec4d.

kotlin-frontend-plugin/examples/frontend-only$ ./gradlew test

> Task :karma-config UP-TO-DATE
A problem was found with the configuration of task ':karma-config'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
 - Directory 'kotlin-frontend-plugin/examples/frontend-only/karma.config.d' specified for property '$1' does not exist.

> Task :karma-run-single FAILED
module.js:545
    throw err;
    ^

Error: Cannot find module 'qunit'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.resolve (internal/module.js:18:19)
    at initQUnit (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma-qunit/lib/index.js:14:39)
    at Array.invoke (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:75:15)
    at Injector.get (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:48:43)
    at kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:166:20
    at Array.forEach (<anonymous>)
    at Server._start (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:165:21)
    at Injector.invoke (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:75:15)
    at Server.start (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:126:18)
    at Object.exports.run (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/cli.js:283:26)
    at Object.<anonymous> (kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':karma-run-single'.
> Process 'command '~/.gradle/nodejs/node-v9.9.0-linux-x64/bin/node'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
11 actionable tasks: 2 executed, 9 up-to-date

Can't get the custom-webpack-config to work

Hi,

I think there are several problems with the custom webpack example project. When I try to run and view it in the browser I get:

Uncaught ReferenceError: reset is not defined

This is because the function is renamed in the browser javascript to reset_0, I solved this issue by executing the javascript as such: js("function() { this.text = "kotlin" }"). This works but the sample still fails to load. Then I had a problem with the index file not being found, I moved it to src/main/web as it was configured this way in the build file. This worked, but still nothing to show. All javascript gets executed correctly, no errors in the console but no vue template is rendered.

Is this example still valid? Has anybody got this thing working?

Thanks

Project Dependencies Not Present in package.json

I'm having a multi project build with three modules A, B, C.
Dependencies are i the same order:
A -> B -> C

Yet, I'm having trouble getting all the dependencies together in a single bundle.

Whenever I build module A I end up having module C present in module "A"s, yet not module B which is declared in my build.gradle:

dependencies {
    compile(":B")
}

Also module C is present in my package.json in my build folder as opposed to module B.

Why is that? And, does it need fixing?

Webpack 4 support

Webpack 4 introduced a new API, including running without any configuration and setting a mode parameter (which is required, I get warnings inside Chrome when running my frontend app).

Are there any plans to upgrade the current default configuration provided by kotlin-frontend-plugin ?

The path of test is included in `resolve.modules` of `webpack.config.js`

The following code seems to be executing filter to remove compileTestKotlin2Js task.

.flatMap { it.tasks.filterIsInstance<Kotlin2JsCompile>() }
.filter { !it.name.contains("test") }

However, it is not filtered because ignorecase = true is not set.

Therefore, the path of test is also included in resolve.modules of webpack.config.js. Is this the expected behavior?

Specify webpack version

I need to specify the webpack and webpack-dev-server versions.

When I use
devDependency("webpack", "2.6.1")
devDependency("webpack-dev-server", "2.4.4")

The package.json output still ends up as
"webpack": "*"
"webpack-dev-server": "*"

How do I specify the webpack and webpack-dev-server versions?

Can't resolve namespaced npm modules

If I add the following npm dependency to the frontend-only example:

dependency "@jetbrains/kotlin-react-dom"

and use the dependency in the main function:

react.dom.render(document.body!!) {}

the build fails with:

Module not found: Error: Can't resolve 'kotlin-react-dom' in '.../kotlin-frontend-plugin/examples/frontend-only/build/js'

I also had to bump the kotlin version to 1.2 to make it compile.

Can't build, a problem occurred configuring project ':kotlinfrontend'

Hi,
when I try to build I get this error message,
I tried multiple configurations of gradle I found online, but nothing works...

this is the message:

* What went wrong:
A problem occurred configuring project ':kotlinfrontend'.
> Failed to notify project evaluation listener.
   > Could not create task of type 'GeneratePackagesJsonTask'.
   > Cannot add task ':kotlinfrontend:npm-preunpack' as a task with that name already exists.
   > Cannot add task ':kotlinfrontend:npm-preunpack' as a task with that name already exists.

this is my current config:

 apply plugin: 'kotlin2js'
 apply plugin: 'org.jetbrains.kotlin.frontend' 
 apply plugin: 'kotlin-dce-js'

 repositories {
      jcenter()
  }

dependencies {
      compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
      compile "org.jetbrains.kotlinx:kotlinx-html:$html_version"
      compile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
      testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}

 kotlinFrontend {
     downloadNodeJsVersion = "latest"

     npm {
         dependency "style-loader"

          devDependency("karma")
     }

     webpackBundle {
           bundleName = "main"
           contentPath = file('src/main/web')
     }

     define "PRODUCTION", false
}

 compileKotlin2Js {
       kotlinOptions.metaInfo = true
       kotlinOptions.outputFile = "${projectDir}/web/js/app.js"
       kotlinOptions.sourceMap = true
       kotlinOptions.moduleKind = 'commonjs'
       kotlinOptions.main = "call"
   }

Someone knows what is going on? Am I doing something wrong?
Thanks in advance...

"No matching version found for [email protected]" with NPM v5+

OS: Mac OS Sierra
Node: 8.0.0
Npm: 5.0.1

Trying to build examples/frontend-only on Mac OS got this error. On Windows and Ubuntu build is successful.

> gradlew build
:npm-preunpack
:npm-configure
:npm-install
npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected]
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'frontend-only'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/name/.npm/_logs/2017-06-06T14_54_18_482Z-debug.log
:npm-install FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':npm-install'.
> npm install failed (exit code = 1)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.804 secs

UPD: It seems that problem is not related to OS. The problem caused by newer versions of npm. Npm v3.10.* which comes with Node v6.* is working as expected. But Npm v5.0.* which comes with Node v8.* ignores modules already installed in node_modules folder (in this case kotlin.js library) and tries to download it from npm repository.
The best solution I've found so far is to change

"dependencies": {
  "kotlin": "1.1.2-4"
}

to

"dependencies": {
    "kotlin": "file:./node_modules/kotlin"
}

and then npm install manually.
After that gradlew bundle is working properly. But after clean the above procedure should be repeated.

frontend-only example does not work

I'm on macOS, no specific web stack configuration (still node/npm are installed).
./gradlew test in the examples/frontend-only folder

A problem was found with the configuration of task ':karma-config'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.

  • Directory '/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/karma.config.d' specified for property '$1' does not exist.

Task :karma-run-single FAILED
internal/modules/cjs/loader.js:573
throw err;
^

Error: Cannot find module 'qunit'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.resolve (internal/modules/cjs/helpers.js:30:19)
at initQUnit (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma-qunit/lib/index.js:14:39)
at Array.invoke (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:75:15)
at Injector.get (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:48:43)
at /Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:169:20
at Array.forEach ()
at Server._start (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:168:21)
at Injector.invoke (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/di/lib/injector.js:75:15)
at Server.start (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/server.js:129:18)
at Object.exports.run (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/lib/cli.js:286:26)
at Object. (/Users/jonnyzzz/Work/kotlin-frontend-plugin/examples/frontend-only/build/node_modules/karma/bin/karma:3:23)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)

FAILURE: Build failed with an exception.

Disable Karma?

It is possible to somehow disable/remove/turn off Karma tasks if I (gasp) dont have or want any unit testing in the project?

frontend-only example fails to build

I cloned master and opened kotlin-frontend-plugin\examples\frontend-only\build.gradle using IntelliJ IDEA 2017.2.5 Community Edition on Windows 10. Building the project produces:

image

Would you mind setting up a .travis.yml that verifies these examples build correctly?

Multi-platform builds fail with kotlin-platform-js

When used together with kotlin-platform-js in a multi-platform build setup, this plugin causes a build error:

A problem occurred evaluating project ':frontend'.
> Platform project project ':frontend' implements non-common project project ':common' (`apply plugin 'kotlin-platform-kotlin'`)

Our configuration of the frontend submodule:

buildscript {
    ext.kotlin_version = '1.1.4-3'

    repositories {
        mavenCentral()
        maven {
            url "https://dl.bintray.com/kotlin/kotlin-eap"
        }
        maven {
            url "https://repo.gradle.org/gradle/libs-releases-local"
        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.21"
    }
}

apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin-platform-js'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    implement project(":common")
}

For reference, here are the top frames of the exception stacktrace:

Caused by: org.gradle.api.GradleException: Platform project project ':frontend' implements non-common project project ':common' (`apply plugin 'kotlin-platform-kotlin'`)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase$addCommonProject$1.invoke(KotlinMultiplatformPlugin.kt:69)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase$addCommonProject$1.invoke(KotlinMultiplatformPlugin.kt:38)
        at org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginKt.whenEvaluated(KotlinMultiplatformPlugin.kt:103)
        at org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginKt.access$whenEvaluated(KotlinMultiplatformPlugin.kt:1)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase.addCommonProject(KotlinMultiplatformPlugin.kt:67)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase.access$addCommonProject(KotlinMultiplatformPlugin.kt:38)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase$apply$3.execute(KotlinMultiplatformPlugin.kt:53)
        at org.jetbrains.kotlin.gradle.plugin.KotlinPlatformImplementationPluginBase$apply$3.execute(KotlinMultiplatformPlugin.kt:38)
        ...

Hot Replacement with multi project

Suppose that you have multi projects and reference another with compile project(...). When you execute gradle run it will start normally (very slow, but normally). But if you change any file referenced project, it won't update the browser with the last version until you clean and compile again (but that will take a lot of time again).

You can force the build but the linked project won't be updated again until the full rebuild.

не добавляются автоматически webpack пакет и его зависимости

Windows 10

сборка демо проекта frontend-only
module.js:471
throw err;
^
Error: Cannot find module 'F:!_KOTLIN\forks\kotlin-frontend-plugin\examples\frontend-only\build\node_modules\webpack\bin\webpack.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
:webpack-bundle FAILED

Если в каталоге Buid добавить вручную через npm install webpack, то все ок.
Изначально webpack присутствует в каталоге пакетов рядом с исполняемым файлов nodejs, но как видно в исходниках резолвится как project.buildDir.resolve("node_modules/webpack/bin/webpack.js")

Или необходимо что то прописать в конфиге что бы собиралось автоматически нужное? (в примерах этого не нашел)

Environment support

How can I define conditional variables to change the application of the custom scripts? I tried defining an environment variable but it didn't work.

karma-run-single does not depend on compile output

I have a common module with tests, and JS module to run them.
The change in the common module does not make the karma-run-single to restart, instead, Gradle reports it is UP-TO-DATE.

I added the following workaround to the project (it's better to correctly set inputs for sure)

//TODO: make runner connect incremental
project.afterEvaluate {
  tasks.getByName("karma-run-single").outputs.upToDateWhen { false }
}

(the task is added later, but why, so I have to have afterEvaluate to hack it)

failed for task ':nodejs-download'.

when execute: ./gradlew :build

Execution failed for task ':nodejs-download'.
> Could not read /IdeaProjects/plugin/build/node-v9.9.0-darwin-x64.tar.gz.
   > java.io.EOFException (no error message)

kotlin-frontend-plugin:0.0.30
kotlin_version = '1.2.21'

IntelliJ IDEA 2017.3.5 (Ultimate Edition)
Build #IU-173.4674.33, built on March 5, 2018

JRE: 1.8.0_152-release-1024-b15 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Mac OS X 10.13.3

Can you help please ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.