@guanghechen/rollup-config
TypeScript icon, indicating that this package has built-in type declarations

6.0.0-alpha.3 • Public • Published

@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.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: []
  • sourcemap: 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
    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

Environment Variables

  • ROLLUP_SHOULD_SOURCEMAP: Determine the default value of Options.sourcemap.

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

    • Default: true

Related

Readme

Keywords

Package Sidebar

Install

npm i @guanghechen/rollup-config

Weekly Downloads

17

Version

6.0.0-alpha.3

License

MIT

Unpacked Size

74.2 kB

Total Files

6

Last publish

Collaborators

  • lemonclown