首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TSC/ Rollup :如何在没有TSC发射文件的情况下将TSC输出输送到卷中?

TSC/ Rollup :如何在没有TSC发射文件的情况下将TSC输出输送到卷中?
EN

Stack Overflow用户
提问于 2022-01-17 21:01:54
回答 1查看 325关注 0票数 0

我正在使用rollup和TSC来生成基于包的es模块。当我运行npm run build时,transpiles .tssrc中的.js文件。之后,Rollup获取.js文件,并执行一些神奇的操作,比如将bare module imports转换为relative imports,使其与浏览器兼容,并将其输出到dist文件夹。

现在的问题是:js如何将TSC的文件的输出“提供”给汇总,而不将它们发送到src文件夹?

我知道noEmit的tsconfig选项,但是我没有js文件可以提供给汇总。

我使用TSC是因为Babel给了我装饰师的问题。

这是命令:

这是文件夹结构。正如您在src文件夹中看到的那样,每个.ts文件都有它的.js文件,这是冗余的,并且在src文件夹中是杂乱的。最好不要将它们保存在那里,而只是用作汇总的输入。

汇总配置

代码语言:javascript
复制
import html from "@web/rollup-plugin-html";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import copy from "rollup-plugin-copy";

export default {
  input: "src/index.html",
  output: { dir: "dist", format: "es", preserveModules: true },
  plugins: [
    html(),
    nodeResolve(),
    copy({
      targets: [{ src: "src/manifest.json", dest: "dist" }],
    }),
  ],
};

tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "incremental": true /* Enable incremental compilation */,
    "target": "es2019" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
    "lib": [
      "ES2019",
      "DOM"
    ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
    "experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */,
    "module": "ESNEXT" /* Specify what module code is generated. */,
    "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
    "rootDirs": [
      "src"
    ] /* Allow multiple folders to be treated as one when resolving modules. */,

    "importHelpers": true /* Allow importing helper functions from tslib once per project, instead of including them per-file. */,
    "noEmitOnError": true /* Disable emitting files if any type checking errors are reported. */,

    "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
    "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
    "esModuleInterop": false /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

  
    "strict": true ,
    "skipLibCheck": true ,
    "pretty": true
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}
EN

回答 1

Stack Overflow用户

发布于 2022-01-18 08:48:51

我的解决方案是将tsc发出的文件输出到src文件夹中的tsc-out文件夹中,并在使用前和后npm脚本之后删除它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70747474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档