[英]How to use Rollup.js to create a common js and named export bundle?
I want to generate a single file to be used by an AWS Lambda using Rollup.js.我想使用 Rollup.js 生成一个供 AWS Lambda 使用的文件。 The bundle must:捆绑包必须:
I'm trying to achieve this but without success.我正在努力实现这一目标,但没有成功。 My current configuration doesn't add Day.js code to the final bundle.我当前的配置没有将 Day.js 代码添加到最终包中。
I created a repository with my attempt .我尝试创建了一个存储库。
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"rollup": "^2.34.2",
The generated bundle can be seen here . 生成的包可以在这里看到。 I don't want these imports in the file:我不希望文件中有这些导入:
const tslib_1 = require("tslib");
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
Instead, I want all the necessary code from tslib
and dayjs
embedded in the file.相反,我希望将来自tslib
和dayjs
的所有必要代码嵌入到文件中。
{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"]
}
The fact is you set tsc
compile your ts
files back to commonjs
causing the issue.事实是您设置tsc
将您的ts
文件编译回commonjs
导致问题。 This job is supposed to be rollup
's instead.这项工作应该是rollup
的。
I would suggest you to leave tsc
transpiles back to esnext
( esm
which is rollup
needs), then you could combine all things with cjs
style.我建议你将tsc
转译留给esnext
( esm
这是rollup
需要),然后你可以将所有东西与cjs
风格结合起来。
Here's the thing you might need to change:这是您可能需要更改的内容:
typescript({
module: 'esnext' // change `commonjs` -> `esnext`
}),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.