【问题标题】:Make TS put all source files, including non-TS, into the build directorymake TS 将所有源文件,包括非 TS,放入 build 目录
【发布时间】:2019-08-24 14:30:45
【问题描述】:

我的文件夹结构如下:

src
└> index.ts
└> image.webp
└> test.html
└> something.css
build
└> index.js
tsconfig.json

如您所见,在我的构建文件夹中,只有构建的索引文件,但没有我的 WEBP、HTML 和 CSS 文件,但我想在构建文件夹中。 有没有办法做到这一点?
我当前的 tsconfig.json:

{
    "compilerOptions": {
      "module": "commonjs",
      "target": "es6",
      "removeComments": true,
      "typeRoots": ["@types"],
      "outDir": "build"
    },
    "exclude": ["node_modules"],
    "include": ["src"]
  }

【问题讨论】:

    标签: typescript tsconfig


    【解决方案1】:

    我相信 tsconfig 是不可能的

    您可以尝试使用copyfiles 编写构建脚本

    "build": "npm-run-all build:*",
    "build:lib": "tsc",
    "build:asset": "copyfiles image.webp test.html some.css build",
    

    您也可以使用webpackCopyPlugin 实现相同的效果

    【讨论】:

    • 就像你链接的网站一样,说只允许 JavaScript 文件,这不是我想要的......
    • 对不起,我误会了
    • 我相信使用 tsconfig 是不可能的,你可以使用 copyfiles 之类的包或使用 webpack 之类的捆绑器
    【解决方案2】:

    @bencergazda 提供了一个解决方案,他创建了 typescript-cp,它的工作方式与您希望的完全一样。

    它与 typescript 并行工作,并读取您的 tsconfig。

    我将它全局安装在我的机器上 is available on npm 并且只是运行“tsc”来进行初始复制构建,然后我添加带有“tsc -w && tscp -w”的脚本以使 typescript 与 typescript 并行工作-cp。

    【讨论】:

    • 您的解决方案无效。我得到了这个“错误:参考''中没有配置'rootDir'”。我正在使用 typeORM
    猜你喜欢
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2020-10-09
    • 1970-01-01
    • 2020-06-30
    相关资源
    最近更新 更多