KotlinJS中的Kootlin失败的世界没有定义
我有一个名为Main.kt
的Kotlin文件
package com.ahp.mui fun main(args: Array<String>) { println("...") println("Hello World") }
项目设置为KotlinJS项目。
一旦我编译,我看到下面的文件正在生成:
target/production/ahp-mui/ahp-mui.js target/production/ahp-mui/ahp-mui.js.map target/production/ahp-mui/ahp-mui.meta.js
主生成的文件包含:
(function (Kotlin) { 'use strict'; var _ = Kotlin.defineRootPackage(null, /** @lends _ */ { com: Kotlin.definePackage(null, /** @lends _.com */ { ahp: Kotlin.definePackage(null, /** @lends _.com.ahp */ { mui: Kotlin.definePackage(null, /** @lends _.com.ahp.mui */ { main_kand9s$: function (args) { Kotlin.println('...'); Kotlin.println('Hello World'); } }) }) }) }); Kotlin.defineModule('ahp-mui', _); _.com.ahp.mui.main_kand9s$([]); }(Kotlin));
现在我把这个文件包含在index.html
中的根目录下:
<html> <head> </head> <body> TESTING <script type="text/javascript" src="target/production/ahp-mui/ahp-mui.js"></script> </body> </html>
现在通过IntelliJ直接提供index.html
文件( http://localhost:63342/ahp-wui/ahp-mui/index.html?_ijt=n55ajlpfutv6b22n56d59jv1rn
),我看到Kotlin
参数没有定义。
ahp-mui.js:16Uncaught ReferenceError: Kotlin is not defined
我正确地做这个? 我是否应该导入任何其他将包括丢失的Kotlin
变量?
IntelliJ应该在某处放置了一个Kotlin标准库.js
文件。 这是在创建项目时配置的。 在编译.js
文件之前,您必须将其包含在HTML文件中。