admin管理员组文章数量:1356258
I am trying to create an npm module that can be used in the browser.
I'm using typescript and rollup.
My tsconfig.json
is:
{
"pilerOptions": {
"module": "CommonJS",
"outDir": "lib",
"strict": true,
"rootDir": "src"
}
}
and my rollup.config.js
is:
import typescript from "@rollup/plugin-typescript";
export default {
input: "src/index.ts",
output: {
dir: "lib",
format: "iife",
},
plugins: [typescript()],
};
Inside src/index.ts
I have the following:
// src/index.ts
import log from './log'
const myFn = () => {
...myFn code
}
My issue is that in the bundle, I get the following:
// lib/index.js bundle
var log_1 = require("./log");
When I actually want to bundle the log
file inside the main lib/index.js
.
How can I do this with Typescript and rollup?
Note: I have tried to add outFile
(ts docs) but that is not supported by "@rollup/plugin-typescript".
Do I have to do the tsc pile myself and then the rollup bundle?
I am trying to create an npm module that can be used in the browser.
I'm using typescript and rollup.
My tsconfig.json
is:
{
"pilerOptions": {
"module": "CommonJS",
"outDir": "lib",
"strict": true,
"rootDir": "src"
}
}
and my rollup.config.js
is:
import typescript from "@rollup/plugin-typescript";
export default {
input: "src/index.ts",
output: {
dir: "lib",
format: "iife",
},
plugins: [typescript()],
};
Inside src/index.ts
I have the following:
// src/index.ts
import log from './log'
const myFn = () => {
...myFn code
}
My issue is that in the bundle, I get the following:
// lib/index.js bundle
var log_1 = require("./log");
When I actually want to bundle the log
file inside the main lib/index.js
.
How can I do this with Typescript and rollup?
Note: I have tried to add outFile
(ts docs) but that is not supported by "@rollup/plugin-typescript".
Do I have to do the tsc pile myself and then the rollup bundle?
Share Improve this question asked Jan 6, 2021 at 10:36 Karl TaylorKarl Taylor 5,2894 gold badges39 silver badges65 bronze badges 2- 1 I'm still looking for an answer to this but if anyone es across this question, I actually moved to Webpack, and it was much simpler. – Karl Taylor Commented Jan 7, 2021 at 12:53
- having a similar issue here it seems :/ stackoverflow./questions/71796571/… No option for webpack unfortunately – eternalStudent Commented Apr 12, 2022 at 10:38
1 Answer
Reset to default 7Rollup requires the TypeScript piler to generate ES Modules in order to properly bundle your code. You'll need to change the module format to "ESNext" instead of "CommonJS" in your tsconfig.json
or change the @rollup/plugin-typescript
configuration in your Rollup config:
typescript({ module: "ESNext" })
As of rollup/plugins#788, you will get a warning if this is not configured correctly.
@rollup/plugin-typescript: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a "module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options.
本文标签: javascriptHow to bundle local typescript files into main bundle using RollupStack Overflow
版权声明:本文标题:javascript - How to bundle local typescript files into main bundle using Rollup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743955990a2568140.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论