It seems we can use typescript to write rollup config file. Say, I can create a file named rollup.config.ts
, with content:
import typescript from 'rollup-plugin-typescript2';
export default {
input: 'main.ts',
plugins: [typescript()],
output: {
file: 'bundle.js',
format: 'cjs',
},
external: ['lodash']
}
It's working if I invoke rollup as rollup -c rollup.config.ts
.
But if I use some typings in it:
import typescript from 'rollup-plugin-typescript2';
import {RollupFileOptions} from "rollup";
const config: RollupFileOptions = {
input: 'main.ts',
plugins: [typescript()],
output: {
file: 'bundle.js',
format: 'cjs',
},
external: ['lodash']
}
export default config;
It will report errors like:
$ rollup -c rollup.config.ts
[!] Error: Unexpected token
rollup.config.ts (4:12)
2: import {RollupFileOptions} from "rollup";
3:
4: const config: RollupFileOptions = {
^
Is it possible to make it work? I tried to use ts-node with
This plugin requires an LTS Node version (v14. 0.0+) and Rollup v2. 14.0+. This plugin also requires at least TypeScript 3.7.
ts rollup generation, you simply need to set dtsRollup. enabled to true in your api-extractor. json config file. By default, the rollup file will be written to "<projectFolder>/dist/<unscopedPackageName>.
The @rollup/plugin-typescript will load any compilerOptions from the tsconfig. json file by default.
This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
You can create your rollup configuration in TypeScript
import { RollupOptions } from "rollup";
const bundle: RollupOptions = {
//...
}
export default bundle
and use it with
rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript
You will need to add rollup.config.ts
to the included files in your tsconfig.json.
{
"include": ["src/**/*", "rollup.config.ts"]
}
With Rollup v2.52.0, you can specify a --configPlugin
option as:
rollup --config rollup.config.ts --configPlugin typescript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With