Koltin 多平台 Javascript IR 构建创建空模块

时间:2021-05-28 08:18:58

标签: javascript kotlin kotlin-multiplatform

我为我们的 Kotlin 多平台项目添加了 JS 目标。该项目名为 STT。

    <!DOCTYPE html>
    <html>
        <head>
        <link rel="stylesheet" href="bootstrap-5.0.1-dist/css/bootstrap.min.css"/>        
        </head>
        <body>
        <div class="jumbotron">
            <h1>Bootstrap</h1>
        </div>
        <script type="text/javascript" src="jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="bootstrap-5.0.1-dist/js/bootstrap.min.js"></script>
      <script>
        $(document).ready(function() {
            $(".jumbotron").click(function() {
                $(this).fadeOut();
            })
        });
      </script>
        </body>
    </html>

当我查看构建文件夹或运行 JS 任务 js(IR) { binaries.executable() browser { commonWebpackConfig { cssSupport.enabled = true } webpackTask { output.libraryTarget = "umd" } } } 时,JS 库看起来是空的。

例如,构建文件夹中的 jsRun

stt.js

本质上是一个空对象

但是,当我使用 BOTH 或 Legacy 时,该文件看起来没问题

(function (root, factory) {
  if (typeof define === 'function' && define.amd)
    define(['exports'], factory);
  else if (typeof exports === 'object')
    factory(module.exports);
  else
    root.stt = factory(typeof sttalg === 'undefined' ? {} : stt);
}(this, function (_) {
  'use strict';
  return _;
}));


我错过了什么?

1 个答案:

答案 0 :(得分:2)

IR 后端默认不会将任何代码导出到 js。您需要将 @JsExport 添加到您想要访问的声明中。见https://kotlinlang.org/docs/js-to-kotlin-interop.html#jsexport-annotation

相关问题