我有一个叫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 (http://localhost:63342/ahp-wui/ahp-mui/index.html?_ijt=n55ajlpfutv6b22n56d59jv1rn)直接提供该Kotlin文件,我看到Kotlin参数没有定义。
ahp-mui.js:16Uncaught ReferenceError: Kotlin is not defined我做得对吗?我是否应该导入将包括缺失的Kotlin变量的其他内容?
发布于 2016-05-30 22:34:52
IntelliJ应该在某个地方设置一个Kotlin标准库.js文件。这是在您创建项目时配置的。您必须在编译的.js文件之前将其包含在HTML中。
https://stackoverflow.com/questions/37533768
复制相似问题