![](/img/trans.png)
[英]What is the best way to pass server side variables to JavaScript on the client side?
[英]Typescript modules in client side - What is the best way?
我正在构建一个 web 应用程序。 我在客户端使用 typescript,在服务器端使用 golang。 我使用 typescript 3.9.2。
我想将.ts
文件编译为.js
,并使用模块。 默认编译将其编译为CommonJS模块加载器。 然后在浏览器中它有一些exports.__...
在第二行。 我搜索了一下,它基本上说它想要一个名为 exports 的变量,但我没有。 在这种情况下,我不喜欢在其他脚本标签中定义模拟导出的主要解决方案。
我将compilerOption
更改为"module":"ES6"
然后它编译并加载良好(在将脚本类型更改为模块之后),但浏览器找不到我要导入的模块。
代码是这样的:
使用.ts
import * as fun from 'funcs'
let bar = fun.foo()
函数.ts
export function foo() :boolean{
return true;
}
使用.js
import * as fun from 'funcs'
var bar = fun.foo()
函数.js
export function foo(){
return true;
}
现在浏览器找不到 use.js 需要的/funcs
use.js
。 当我手动将use.js
中的第一行更改为
import * as fun from 'funcs.js'
有用。
我该怎么做才能使一切自动化? 这里的最佳做法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.