@guanghechen/rollup-config

Rollup configs for bundle typescript project

Usage no npm install needed!

<script type="module">
  import guanghechenRollupConfig from 'https://cdn.skypack.dev/@guanghechen/rollup-config';
</script>

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: []
  • shouldSourceMap: Whether if generate sourcemaps.

  • shouldExternalAll: Whether if make all dependencies external.

  • 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 of Options.shouldSourceMap.

    • Default: true
  • ROLLUP_EXTERNAL_ALL_DEPENDENCIES: Determine the default value of Options.shouldExternalAll.

    • Default: true

Related