Reputation: 5379
I want to generate a single file to be used by an AWS Lambda using Rollup.js. 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.
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.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs"
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"]
}
Upvotes: 1
Views: 1482
Reputation: 17474
The fact is you set tsc
compile your ts
files back to commonjs
causing the issue. This job is supposed to be rollup
's instead.
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.
Here's the thing you might need to change:
typescript({
module: 'esnext' // change `commonjs` -> `esnext`
}),
Upvotes: 1