brattonross / vite-plugin-voie

File system based routing plugin for Vite
https://www.npmjs.com/package/vite-plugin-voie
MIT License
230 stars 9 forks source link

Consolidate plugin API #16

Open brattonross opened 3 years ago

brattonross commented 3 years ago

Since we now support globs for the pagesDir option I think we can clean up the plugin API somewhat. Here's my initial idea for what it should look like:

// Use a string to set the pages directory, uses the default extensions
voie({
  pages: 'src/views'
})

// Use an object to set the directory and/or the extensions
voie({
  pages: {
    dir: 'src/views',
    extensions: ['ts']
  }
})

// Use an array to specify a list of directories to use
// Object syntax can be used inside the array if extensions need to be customized per-directory
voie({
  pages: [
    'module-a/pages',
    { dir: 'module-b/pages', extensions: ['ts', 'vue'] }
  ]
})

// Use an object with `dir` as an array when you want to set custom extensions for all paths
// Extensions can still be specified per-directory, so in this example
// ['ts'] will be used for `module-b/pages`, and ['tsx'] will be used for `module-a/pages`.
voie({
  pages: {
    dir: [
      'module-a/pages',
      { dir: 'module-b/pages', extensions: ['ts'] }
    ],
    extensions: ['tsx']
  }
})