我正在使用rollup和TSC来生成基于包的es模块。当我运行npm run build时,transpiles .ts到src中的.js文件。之后,Rollup获取.js文件,并执行一些神奇的操作,比如将bare module imports转换为relative imports,使其与浏览器兼容,并将其输出到dist文件夹。
现在的问题是:js如何将TSC的文件的输出“提供”给汇总,而不将它们发送到src文件夹?。
我知道noEmit的tsconfig选项,但是我没有js文件可以提供给汇总。
我使用TSC是因为Babel给了我装饰师的问题。
这是命令:

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

汇总配置
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
{
"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"]
}发布于 2022-01-18 08:48:51
我的解决方案是将tsc发出的文件输出到src文件夹中的tsc-out文件夹中,并在使用前和后npm脚本之后删除它。
https://stackoverflow.com/questions/70747474
复制相似问题