【问题标题】:Transpile .ts source files without dependant configuration files转译 .ts 源文件,无需依赖配置文件
【发布时间】:2019-07-02 23:36:47
【问题描述】:

我以这种方式在 typescript 中设置我的 node.js 服务器:

/src
  /...
/dist
/node_modules
  /...
/tsconfig.json
/..other conf and typings files

/src 中的一些文件例如从 package.json 获取一些配置。这使得转译器在 dist 中创建这个层次结构:

/dist
  /src
    /...js files
  /package.json

我的 tsconfig.json 如下:

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "resolveJsonModule": true
    },
    "include": [
        "src/**/*",
        "typings-custom/**/*.ts"
    ],
    "exclude": [
        "./package.json"
    ]
}

我想知道是否可以从 dist 文件夹中排除一些依赖项,因为 /src 和 /dist 之间的相对路径保持不变

提前致谢。

【问题讨论】:

  • 能否请您发布您的tsconfig.json 文件?而且我怀疑如果您的源文件依赖于您的package.json 中的值,则需要进入/dist 目录,以便客户端可以访问它。
  • 我用 tsconfig 编辑了我的问题。客户端不会访问它,因为这是服务器。这些值仅在服务器启动期间使用

标签: node.js typescript tsc


【解决方案1】:

我终于通过使用 const { propertyA, propertyB } = require("../package.json"); 解决了我的问题 有人可以解释一下为什么在这种情况下转译器不复制文件?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-24
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    相关资源
    最近更新 更多