首页 > 解决方案 > 如何通过打字稿模块制作节点模块

问题描述

如何将 typescript 模块构建为 javascript 模块

这是我的 tsconfigFile

{
  "compilerOptions": {
    "target": "ES5",
    "module": "CommonJS",
    "declaration": true,
    "outDir": "./dist",
    "strict": true,
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}

我想建立这个代码 --------------

打字稿模块

import getData from './getData';


export default {
 getData 
};

节点模块

const getData = require("./getData")';

module.exports = {
  getData
};

标签: javascriptnode.jstypescriptnode-modulesmodule-build

解决方案


由于您的配置似乎具有生成节点模块所需的设置,我认为您只需要运行tsc命令,它就会生成 JS 代码并将其存储在./dist目录中。


推荐阅读