【问题标题】:Koltin multiplatform Javascript IR build creates empty moduleKotlin 多平台 Javascript 或构建创建空模块
【发布时间】:2021-05-28 08:18:58
【问题描述】:

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

  js(IR) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
            webpackTask {
                output.libraryTarget = "umd"
            }
        }
    }

当我查看构建文件夹或运行 JS 任务 jsRun 时,JS 库看起来是空的。

这里是例如构建文件夹中的stt.js

(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 _;
}));


本质上是一个空对象

但是,当我使用 BOTH 或 Legacy 时,该文件看起来还可以

js(LEGACY) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
            webpackTask {
                output.libraryTarget = "umd"
            }
        }
    }

我错过了什么?

【问题讨论】:

    标签: javascript kotlin kotlin-multiplatform


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      相关资源
      最近更新 更多