marp-team / marp-cli

A CLI interface for Marp and Marpit based converters
MIT License
1.85k stars 105 forks source link

ES Modules for the configuration file #534

Closed yhatt closed 1 year ago

yhatt commented 1 year ago

Updated cosmiconfig to the latest version, and supported ES Modules in the configuration file.

// marp.config.mjs
export default {
  allowLocalFiles: true,
  html: true,
  engine: ({ marp }) => marp.use(somePlugin)
}

Jest and pkg are not yet supported ES Modules due to the segmentation fault when running dynamic import import(). :(


This PR is also including another improvement for the config: Export Config type to allow better experience while writing a config in IDE. @type JSDoc annotation is available in both of CommonJS and ES Modules.

/** @type {import('@marp-team/marp-cli').Config} */
const config = {
  // ...
}

export default config

If user want to swap the engine from Marp Core, Config type also can provide a suitable type for the swapped engine.

/** @type {import('@marp-team/marp-cli').Config<typeof import('@marp-team/marpit').Marpit>} */
const config = {
  engine: '@marp-team/marpit',
  options: {
    // Only suggests Marpit constructor options, not Marp Core options
  }
}

export default config