how to add @microsoft/api-extractor to a rollup.config.mjs file? in javascript

To use @microsoft/api-extractor in a Rollup project, you need to do the following:

  1. Install @rollup/plugin-commonjs and @rollup/plugin-node-resolve packages as devDependencies
  2. Install @microsoft/api-extractor as devDependencies
  3. Create a rollup.config.mjs file in your project
  4. Add configuration options to your rollup.config.mjs to include api-extractor

Here's an example of the rollup.config.mjs file with api-extractor configuration options:

index.tsx
// rollup.config.mjs
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import apiExtractor from '@microsoft/api-extractor';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/index.js',
    format: 'cjs'
  },
  plugins: [
    resolve(),
    commonjs(),
    apiExtractor({
      configType: 'release',      // Specify the API Extractor config file that's used (can be 'dev' or 'release')
      reportFileName: 'api-report.md', // Specify the name of the output file for the operation report
      projectFolder: './',        // Specify the folder for the API Extractor project (relative or absolute path)
      tsconfigFilePath: 'path/to/tsconfig.json' // Specify the path of the tsconfig.json file
    })
  ]
}
780 chars
23 lines

Once you have your rollup.config.mjs file configured, you can run rollup to build your project and api-extractor will generate its output files according to the apiExtractor options that you've specified.

Note: Make sure to set your tsconfig.json to "declaration": true , to enable TypeScript to emit declarations (type definitions) for your code that api-extractor will use to generate the documentation.

gistlibby LogSnag