README
@guanghechen/rollup-config
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.js
import createRollupConfig from '@guanghechen/rollup-config' import manifest from './package.json' const config = createRollupConfig({ manifest, pluginOptions: { typescriptOptions: { tsconfig: 'tsconfig.src.json', }, } }) export default config
In monorepo such as lerna or yarn, put the following code at the
<Monorepo Root>/rollup.config.js
:import createRollupConfig from '@guanghechen/rollup-config' import path from 'path' async function rollupConfig() { const { default: manifest } = await import(path.resolve('package.json')) const config = createRollupConfig({ manifest, pluginOptions: { typescriptOptions: { tsconfig: 'tsconfig.src.json' }, }, }) return config } export default rollupConfig()
Then in every package.json of sub-packages, set the scripts field like:
"scripts" { "prebuild": "rimraf lib/ && tsc -p tsconfig.src.json --emitDeclarationOnly", "build": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js", "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:
shouldSourceMap
: 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 dependencies
Record<string, string> | string[]
false
Dependency list peerDependencies
Record<string, string> | string[]
false
Peer dependency list optionalDependencies
Record<string, string> | string[]
false
Optional dependency list 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
Environment Variables
ROLLUP_SHOULD_SOURCEMAP
: Determine the default value ofOptions.shouldSourceMap
.- Default:
true
- Default:
ROLLUP_EXTERNAL_ALL_DEPENDENCIES
: Determine the default value ofOptions.shouldExternalAll
.- Default:
true
- Default: