gpt4 book ai didi

node.js - 如何在 Scala.js 中使用 Node 模块

转载 作者:搜寻专家 更新时间:2023-10-31 23:34:41 25 4
gpt4 key购买 nike

我刚开始使用 Scala.js,想将现有的基于 Node 的 JavaScript 应用程序移植到 Scala.js。第一个问题:我需要包含 mysql 模块 https://github.com/mysqljs/mysql从 Scala.js 访问 MySQL。

最佳答案

这需要几个步骤:

  • 添加ScalaJSBundlerPlugin到你的 plugins.sbt ( example )
  • 在你的 build.sbt ( example ) 中启用插件
  • 为您的 Node 模块 ( example for node-fetch ) 创建一个外观(可以是最小的),用类似 @JSImport("node-fetch", JSImport.Namespace) 的东西定义一个对象
  • 在你的 build.sbt ( example ) 中添加 npmDependencies
  • 创建自定义 webpack 配置,将 Node 配置为目标 (example)

关于node.js - 如何在 Scala.js 中使用 Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40818082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com