zombieyang / puerts_unity_webgl_demo

在Unity里用Typescript写小游戏/Web游戏
BSD 3-Clause "New" or "Revised" License
181 stars 63 forks source link

在微信小游戏中该如何解决require的resolve path的问题 #43

Closed pkujhd closed 1 year ago

pkujhd commented 1 year ago

如果有的工程中require了npm的某些包以及csharp, 该如何适配?因为在tsconfig中增加了path,所以require的path都是简单化的.

在browser和app版本中puerts使用genRequire得到一个require函数,并且使用这个require来解决path的问题,但是在wechat_minigame中require并没有被修改成功. 而且即使修改成功了最后也会走向puerts.evalScript,而eval被禁止了

zombieyang commented 1 year ago

https://github.com/zombieyang/puerts_unity_webgl_demo/wiki/%E5%A6%82%E4%BD%95%E4%BB%8E%E5%8E%9F%E6%9C%89%E7%9A%84PuerTS%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%BF%81%E7%A7%BB%E8%BF%87%E6%9D%A5%EF%BC%9F

这里有提到,要上小游戏就不能用require,都改成用ExecuteModule 另外小游戏里因为没有node api,不是所有npm包都支持。所以最好先用打包工具把npm包单独build出来。

pkujhd commented 1 year ago

ok, thx

pkujhd commented 1 year ago

https://github.com/zombieyang/puerts_unity_webgl_demo/wiki/%E5%A6%82%E4%BD%95%E4%BB%8E%E5%8E%9F%E6%9C%89%E7%9A%84PuerTS%E9%A1%B9%E7%9B%AE%E4%B8%AD%E8%BF%81%E7%A7%BB%E8%BF%87%E6%9D%A5%EF%BC%9F

这里有提到,要上小游戏就不能用require,都改成用ExecuteModule 另外小游戏里因为没有node api,不是所有npm包都支持。所以最好先用打包工具把npm包单独build出来。

能方便问一下,推荐使用啥工具来处理npm package 么?

zombieyang commented 1 year ago

我习惯用webpack,也有人用rollup

类似例子: https://github.com/zombieyang/puerts-ts-loader/blob/main/upm/Samples~/Sample2/Puer-Project/webpack.config.js