Rollup configs for bundle typescript project.
-
npm
npm install --save-dev @guanghechen/rollup-config
-
yarn
yarn add --dev @guanghechen/rollup-config
-
Use in
rollup.config.mjs
import createRollupConfig from '@guanghechen/rollup-config' import manifest from './package.json' assert { type: "json" } export default createRollupConfig({ manifest, pluginOptions: { typescriptOptions: { tsconfig: 'tsconfig.lib.json', }, } })
-
In monorepo such as lerna or yarn, put the following code at the
<Monorepo Root>/rollup.config.mjs
:import createRollupConfig from '@guanghechen/rollup-config' import path from 'node:path' export default async function rollupConfig() { const { default: manifest } = await import( path.resolve('package.json'), { assert: { type: "json" } }, ) const config = await createRollupConfig({ manifest, pluginOptions: { typescriptOptions: { tsconfig: 'tsconfig.lib.json' }, }, }) return config }
Then in every package.json of sub-packages, set the scripts field like:
"scripts" { "build": "cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs", "prebuild": "rimraf lib/", "prepublishOnly": "cross-env ROLLUP_SHOULD_SOURCEMAP=false yarn build", }
The package.json will loaded as
manifest
option.
Extended from rollup.InputOptions.
-
additionalPlugins
: Additional rollup plugins (appended after the preset plugins).- Type:
string[]
- Required:
false
- Default:
[]
- Type:
-
sourcemap
: Whether if generate sourcemaps.- Type:
boolean
- Required:
false
- Default: Depends on Environment Params
- Type:
-
shouldExternalAll
: Whether if make all dependencies external.- Type:
boolean
- Required:
false
- Default: Depends on Environment Params
- Type:
-
manifest
property type required description source
string
true
Source entry file main
string
false
Target entry file for cjs bundles module
string
false
Target entry file for es bundles types
string
false
Target entry file for ts types dependencies
`Record<string, string> string[]` false
peerDependencies
`Record<string, string> string[]` false
optionalDependencies
`Record<string, string> string[]` false
-
pluginOptions
property type required description commonjsOptions
object
false
Options for @rollup/plugin-commonjs jsonOptions
object
false
Options for @rollup/plugin-json nodeResolveOptions
object
false
Options for @rollup/plugin-node-resolve typescriptOptions
object
false
Options for @rollup/plugin-typescript dtsOptions
object
false
Options for rollup-plugin-dts
-
ROLLUP_SHOULD_SOURCEMAP
: Determine the default value ofOptions.sourcemap
.- Default:
true
- Default:
-
ROLLUP_EXTERNAL_ALL_DEPENDENCIES
: Determine the default value ofOptions.shouldExternalAll
.- Default:
true
- Default: