@guanghechen/rollup-config
v6.0.0-alpha.3
Published
Rollup configs for bundle typescript project
Downloads
134
Readme
Rollup configs for bundle typescript project.
Install
npm
npm install --save-dev @guanghechen/rollup-config
yarn
yarn add --dev @guanghechen/rollup-config
Usage
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.src.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.src.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.
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 filemain
|string
|false
| Target entry file for cjs bundlesmodule
|string
|false
| Target entry file for es bundlestypes
|string
|false
| Target entry file for ts typesdependencies
|Record<string, string> | string[]
|false
| Dependency listpeerDependencies
|Record<string, string> | string[]
|false
| Peer dependency listoptionalDependencies
|Record<string, string> | string[]
|false
| Optional dependency listpluginOptions
property | type | required | description :--------------------:|:---------:|:---------:|:------------------------
commonjsOptions
|object
|false
| Options for @rollup/plugin-commonjsjsonOptions
|object
|false
| Options for @rollup/plugin-jsonnodeResolveOptions
|object
|false
| Options for @rollup/plugin-node-resolvetypescriptOptions
|object
|false
| Options for @rollup/plugin-typescriptdtsOptions
|object
|false
| Options for rollup-plugin-dts
Environment Variables
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: