-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This uses the Kotlin JS output to build a web application
- Loading branch information
Showing
18 changed files
with
1,372 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import %workspace%/../../common.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Add rules here to build your software | ||
# See https://docs.bazel.build/versions/master/build-ref.html#BUILD_files | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "http_server", "rollup_bundle") | ||
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package") | ||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_js_library") | ||
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test") | ||
|
||
# Grab a Maven dependency | ||
kt_js_import( | ||
name = "kotlinx-html-js", | ||
jars = ["@maven//:v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar"], | ||
srcjar = "@maven//:v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar", | ||
) | ||
|
||
# This will create hello.js | ||
kt_js_library( | ||
name = "hello", | ||
srcs = [":HelloWorld.kt"], | ||
deps = [":kotlinx-html-js"], | ||
) | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
srcs = ["hello.js"], | ||
entry_point = "bootstrap.js", | ||
deps = [ | ||
"@npm//kotlin", | ||
"@npm//kotlinx-html-js", | ||
], | ||
) | ||
|
||
web_package( | ||
name = "package", | ||
assets = [ | ||
# For differential loading, we supply both an ESModule entry point and an es5 entry point | ||
# The injector will put two complimentary script tags in the index.html | ||
":bundle.min.js", | ||
":bundle.min.es2015.js", | ||
], | ||
data = [":bundle"], | ||
index_html = "index.html", | ||
) | ||
|
||
http_server( | ||
name = "server", | ||
data = [":package"], | ||
templated_args = ["package"], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["spec.js"], | ||
data = [ | ||
":bundle", | ||
":bundle.js", | ||
"@npm//domino", | ||
], | ||
templated_args = ["--node_options=--experimental-modules"], | ||
) | ||
|
||
# For testing from the root workspace of this repository with bazel_integration_test. | ||
filegroup( | ||
name = "all_files", | ||
srcs = glob( | ||
include = ["**/*"], | ||
exclude = [ | ||
"bazel-out/**/*", | ||
"dist/**/*", | ||
"node_modules/**/*", | ||
], | ||
), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import kotlin.browser.* | ||
import kotlinx.html.* | ||
import kotlinx.html.dom.* | ||
|
||
fun printHello() { | ||
document.body!!.append.div { | ||
span { | ||
+"Hello from Kotlin!" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
workspace( | ||
name = "kotlin_example", | ||
managed_directories = {"@npm": ["node_modules"]}, | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "build_bazel_rules_nodejs", | ||
sha256 = "da72ea53fa1cb8ab5ef7781ba06b97259b7d579a431ce480476266bc81bdf21d", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.36.2/rules_nodejs-0.36.2.tar.gz"], | ||
) | ||
|
||
# Install external npm dependencies | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install") | ||
|
||
npm_install( | ||
# Name this npm so that Bazel Label references look like @npm//package | ||
name = "npm", | ||
package_json = "//:package.json", | ||
package_lock_json = "//:package-lock.json", | ||
) | ||
|
||
# Install any Bazel rules which were extracted earlier by the yarn_install rule. | ||
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies") | ||
|
||
install_bazel_dependencies() | ||
|
||
# Install external Kotlin/Java dependencies | ||
http_archive( | ||
name = "rules_jvm_external", | ||
sha256 = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74", | ||
strip_prefix = "rules_jvm_external-2.7", | ||
url = "https://github.com/bazelbuild/rules_jvm_external/archive/2.7.zip", | ||
) | ||
|
||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
|
||
maven_install( | ||
name = "maven", | ||
artifacts = [ | ||
"org.jetbrains.kotlinx:kotlinx-html-js:0.6.12", | ||
"org.jetbrains.kotlin:kotlin-stdlib-js:1.2.71", | ||
], | ||
fetch_sources = True, # Fetch source jars. Defaults to False. | ||
maven_install_json = "@kotlin_example//:maven_install.json", | ||
repositories = [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html/", | ||
"https://maven.google.com", | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
|
||
load("@maven//:defs.bzl", "pinned_maven_install") | ||
|
||
pinned_maven_install() | ||
|
||
# To test local edits, add this to .bazelrc.user: | ||
# build --override_repository=io_bazel_rules_kotlin=/my/path/to/rules_kotlin | ||
rules_kotlin_version = "40efd46789a06f06655e867dcaec2a84815461df" | ||
|
||
http_archive( | ||
name = "io_bazel_rules_kotlin", | ||
#sha256 = "fea280c0c3fbb40712c5e7994c36c1a7ab0be5c8d26c90d47ac55860c5d43b2d", | ||
strip_prefix = "rules_kotlin-%s" % rules_kotlin_version, | ||
type = "zip", | ||
urls = ["https://github.com/bazelbuild/rules_kotlin/archive/%s.zip" % rules_kotlin_version], | ||
) | ||
|
||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") | ||
|
||
kotlin_repositories() | ||
|
||
kt_register_toolchains() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// hello.js is created by the kt_js_library rule | ||
import('./hello.js') | ||
// we dynamic load the Kotlin code because it brings in a Kotlin runtime dependency | ||
// In a real app we'd want to avoid doing that until the user visits a part of the application that requires it | ||
.then(m => | ||
// Kotlin's JS emit will create a default export object | ||
// it has the function printHello that we defined in HelloWorld.kt | ||
m.default.printHello()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>rules_kotlin webapp example</title> | ||
<link rel="icon" href="/favicon.png"> | ||
<!-- CSS will be linked here --> | ||
</head> | ||
<!-- JS scripts will be included here --> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
{ | ||
"dependency_tree": { | ||
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": 1276653619, | ||
"conflict_resolution": {}, | ||
"dependencies": [ | ||
{ | ||
"coord": "org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71", | ||
"dependencies": [], | ||
"directDependencies": [], | ||
"file": "v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html//org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar", | ||
"https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar", | ||
"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar" | ||
], | ||
"sha256": "63999687ff2fce8a592dd180ffbbf8f1d21c26b4044c55cdc74ff3cf3b3cf328", | ||
"url": "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71", | ||
"dependencies": [], | ||
"directDependencies": [], | ||
"file": "v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71-sources.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html//org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71-sources.jar", | ||
"https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71-sources.jar", | ||
"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71-sources.jar" | ||
], | ||
"sha256": "e947bbdd1f6d3afd69ce01598327a9923b11b725f1bfc140340aca0fcfcf173a", | ||
"url": "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-common/1.2.71/kotlin-stdlib-common-1.2.71-sources.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlin:kotlin-stdlib-js:1.2.71", | ||
"dependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71" | ||
], | ||
"file": "v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html//org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71.jar", | ||
"https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71.jar", | ||
"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71.jar" | ||
], | ||
"sha256": "1c8b11025a9bbc22d27d9b8abf0d6f7c91a9e5460979ec37b686d3da0efcf79b", | ||
"url": "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlin:kotlin-stdlib-js:jar:sources:1.2.71", | ||
"dependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71" | ||
], | ||
"file": "v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71-sources.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html//org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71-sources.jar", | ||
"https://maven.google.com/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71-sources.jar", | ||
"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71-sources.jar" | ||
], | ||
"sha256": "5a126625080701aca06f5d5d675a37566afbc375cacdfd6968b54fe1f849dc5f", | ||
"url": "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-js/1.2.71/kotlin-stdlib-js-1.2.71-sources.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlinx:kotlinx-html-common:0.6.12", | ||
"dependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71" | ||
], | ||
"file": "v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12.jar", | ||
"https://maven.google.comorg/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12.jar", | ||
"https://repo1.maven.org/maven2org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12.jar" | ||
], | ||
"sha256": "ecf6d7595bdd762c4e835cd9196df7b014f51542d8266575343e8acbf0beb825", | ||
"url": "http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlinx:kotlinx-html-common:jar:sources:0.6.12", | ||
"dependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71" | ||
], | ||
"file": "v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12-sources.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12-sources.jar", | ||
"https://maven.google.comorg/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12-sources.jar", | ||
"https://repo1.maven.org/maven2org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12-sources.jar" | ||
], | ||
"sha256": "1ee01561bd105933e282e024ced9220a520f8f42d7e80eada3bd522cc04fb35b", | ||
"url": "http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-common/0.6.12/kotlinx-html-common-0.6.12-sources.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlinx:kotlinx-html-js:0.6.12", | ||
"dependencies": [ | ||
"org.jetbrains.kotlinx:kotlinx-html-common:0.6.12", | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.2.71", | ||
"org.jetbrains.kotlin:kotlin-stdlib-js:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-js:1.2.71", | ||
"org.jetbrains.kotlinx:kotlinx-html-common:0.6.12" | ||
], | ||
"file": "v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar", | ||
"https://maven.google.comorg/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar", | ||
"https://repo1.maven.org/maven2org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar" | ||
], | ||
"sha256": "c62f5577ecfb6452c950f7e4d6faed9c016049eb2e6744099579fd888b071999", | ||
"url": "http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar" | ||
}, | ||
{ | ||
"coord": "org.jetbrains.kotlinx:kotlinx-html-js:jar:sources:0.6.12", | ||
"dependencies": [ | ||
"org.jetbrains.kotlinx:kotlinx-html-common:jar:sources:0.6.12", | ||
"org.jetbrains.kotlin:kotlin-stdlib-common:jar:sources:1.2.71", | ||
"org.jetbrains.kotlin:kotlin-stdlib-js:jar:sources:1.2.71" | ||
], | ||
"directDependencies": [ | ||
"org.jetbrains.kotlin:kotlin-stdlib-js:jar:sources:1.2.71", | ||
"org.jetbrains.kotlinx:kotlinx-html-common:jar:sources:0.6.12" | ||
], | ||
"file": "v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar", | ||
"mirror_urls": [ | ||
"http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar", | ||
"https://maven.google.comorg/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar", | ||
"https://repo1.maven.org/maven2org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar" | ||
], | ||
"sha256": "58dd80d73af41e0e2bc0c50df66302411bca3b0cb69c071b5b135015285accb7", | ||
"url": "http://dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar" | ||
} | ||
], | ||
"version": "0.1.0" | ||
} | ||
} |
Oops, something went wrong.