打字稿编译文件,导入其他文件并扩展文件模块解析

问题描述

这是一个简单的问题演示,没有webpack,仅typescript,使用tsc.ts文件编译为.js文件,并运行快速应用程序静态文件。使用浏览器esmodule解析。

但已编译的文件,导入语句不具有.js扩展名

<!-- index.html  -->

<script src='./dist/index.js' type='module'></script>
// index.ts
import a from 'a';

console.log(a)

// a.ts
const a:number = 1;
export default const a;
// tsconfig
{
   "target": "ES5","module": "es2015","lib": ["DOM","ES2015","ES2017"],"outDir": "./dist","moduleResolution": "node","baseUrl": "./" 
}

编译tsc之后,index.js文件如下所示

// compiled index.js
import a from 'a';
console.log(a)

将这个dist文件夹存储在服务器上

诸如xxxx/static/a的静态资源请求,没有扩展.js,并且找不到404。

编译后如何保存文件ext,我的意思是将这个.js保留在导入语句中

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)