[英]How to transpile typescript with imported modules to a browser friendly js-file
I am struggling with transpiling ts for some time now.一段时间以来,我一直在努力转换 ts。 I have an npm package with typescript files and some node_modules all linked together.我有一个 npm package 与 typescript 文件和一些 node_modules 所有链接在一起。
// example.ts
import * as bootstrap from 'bootstrap';
export default () => {
const popoverList = document.querySelectorAll('.popover');
popoverList.foreach((popover) => {
new bootstrap.Popover(popover)
})
}
And in another file:在另一个文件中:
// maint.ts
import initPopovers from './example';
initPopovers();
And off course a lot more in and exports.当然还有更多的进出。 The problem is that i want this entrypoint (main.ts) to be transpiled to main.js and all the files included from node_modules baked into it.问题是我希望将此入口点 (main.ts) 转换为 main.js 并将 node_modules 中包含的所有文件都烘焙到其中。 No modules anymore but just plain old js that works out of the box in the browser.不再有模块,只有在浏览器中开箱即用的普通旧 js。 I tried many different things but none of them worked.我尝试了很多不同的东西,但没有一个奏效。 The best one was browserify but with Typescript this did not work as expected.最好的是 browserify,但对于 Typescript,这并没有按预期工作。
Does someone have the solution for me?有人为我提供解决方案吗?
Thanks!谢谢!
Maybe tsup
works for you?也许tsup
适合你? It's based on esbuild
and should do exactly that: https://github.com/egoist/tsup .它基于esbuild
并且应该完全做到这一点: https://github.com/egoist/tsup 。
What you're looking for is called a bundler
(along with a transpiler), there are several others.您正在寻找的东西称为bundler
器(连同转译器),还有其他几个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.