All Projects → Kotlin → Kotlin Frontend Plugin

Kotlin / Kotlin Frontend Plugin

Licence: apache-2.0
Gradle Kotlin (http://kotlinlang.org) plugin for frontend development

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlin Frontend Plugin

Typescript Webpack Starter
⚡ create-ts-lib: A Starter Kit and a CLI to create your TypeScript / ES6 module bundled by Webpack without thinking about build or unit tests configurations. 🏠
Stars: ✭ 358 (-38.06%)
Mutual labels:  webpack, npm, karma
Angularjs Webpack Starter
🚀 A modern frontend setup for AngularJS projects using NPM, TypeScript and Webpack.
Stars: ✭ 173 (-70.07%)
Mutual labels:  webpack, npm, karma
React Cordova Boilerplate
TodoMVC example for react with development tools to build a cordova application
Stars: ✭ 206 (-64.36%)
Mutual labels:  webpack, karma
Fullstacktemplate
A Template for Creating a Full Stack Web Application with Python, NPM, Webpack and React
Stars: ✭ 223 (-61.42%)
Mutual labels:  webpack, npm
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (-47.06%)
Mutual labels:  webpack, npm
100 Days Of Code Frontend
Curriculum for learning front-end development during #100DaysOfCode.
Stars: ✭ 2,419 (+318.51%)
Mutual labels:  webpack, npm
Webpack Static Html Pages
Webpack template/example with multiple static html pages
Stars: ✭ 202 (-65.05%)
Mutual labels:  webpack, npm
21 Points
❤️ 21-Points Health is an app you can use to monitor your health.
Stars: ✭ 244 (-57.79%)
Mutual labels:  webpack, gradle
Goa
基于Beego开发的问答系统
Stars: ✭ 154 (-73.36%)
Mutual labels:  webpack, npm
React Rock Paper Scissors
Rock Paper Scissors game built with ReactJS
Stars: ✭ 324 (-43.94%)
Mutual labels:  webpack, karma
Front End Doc
前端文档汇总(觉得对您有用的话,别忘了star收藏哦^_^ !)
Stars: ✭ 372 (-35.64%)
Mutual labels:  webpack, npm
Spring Boot Angular2
spring boot backend, angular2 frontend with webpack, typescript, sass, bootstrap4, karma, jasmine
Stars: ✭ 396 (-31.49%)
Mutual labels:  gradle, karma
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (-71.45%)
Mutual labels:  webpack, karma
Scalajs Bundler
Stars: ✭ 206 (-64.36%)
Mutual labels:  webpack, npm
Reactn
React, but with built-in global state management.
Stars: ✭ 1,906 (+229.76%)
Mutual labels:  webpack, npm
Ol3echarts
🌏 📊 ol3Echarts | a openlayers extension to echarts
Stars: ✭ 229 (-60.38%)
Mutual labels:  webpack, karma
Modern Wasm Starter
🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Stars: ✭ 140 (-75.78%)
Mutual labels:  webpack, npm
Spring Boot Angular4 Boilerplate
Quickstart for spring boot + angular 4 projects
Stars: ✭ 151 (-73.88%)
Mutual labels:  webpack, gradle
Ionic Boilerplate
✨ An Ionic Starter kit featuring Tests, E2E, Karma, Protractor, Jasmine, Istanbul, Gitlab CI, Automatic IPA and APK, TypeScript 2, TsLint, Codelyzer, Typedoc, Yarn, Rollup, and Webpack 2
Stars: ✭ 309 (-46.54%)
Mutual labels:  webpack, karma
Burnside
Fast and Reliable E2E Web Testing with only Javascript
Stars: ✭ 389 (-32.7%)
Mutual labels:  webpack, karma

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].