简体   繁体   English

在 Next JS 中导入动态的打字稿文件

[英]Import dynamic a typescript file in Next JS

According NextJs documentation we can use dynamic import for javascripts files const DynamicComponent = dynamic(() => import('../components/hello')) .根据 NextJs 文档,我们可以对 javascripts 文件使用动态导入const DynamicComponent = dynamic(() => import('../components/hello'))
Will be correct to use dynamic import also for .tsx file like this:将动态导入也用于.tsx文件是正确的,如下所示:

 const MyComponent = dynamic(() => import('main/my-file.tsx'), { ssr: false, });

? ? Or we can import dynamically only .js files?或者我们只能动态导入.js文件?

I guess you can dynamically import ts files in nextjs with some workarounds.我想您可以通过一些解决方法在 nextjs 中动态导入ts文件。

import dynamic from "next/dynamic";
...
...
const Button = dynamic(() => import("../components/Button").then(module => module.default));

If you want to read further https://github.com/vercel/next.js/issues/4515如果您想进一步阅读https://github.com/vercel/next.js/issues/4515

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM