rolldown-old / old-rolldown

Modern bundler built on Rollup with couple more features, such as multiple entry points, presets, better configuration experience and more.
MIT License
72 stars 1 forks source link

more API #2

Open tunnckoCore opened 7 years ago

tunnckoCore commented 7 years ago
rolldown.transform = (source, options) => {
  if (!source) {
    // or something like that
    // (need more strict check for that param)
    return Promise.reject(new TypeError('expect a string'))
  }

  return utils.tmpFile(source).then((file) => {
    options.entry = file.path
    delete options['source']

    // we don't want to (force to not) write to disk
    // but resolve `{ code, map }` object
    delete options['targets']
    delete options['dest']

    return rolldown(options)
  })
}

rolldown.plugin = (plugin, options) => {
  rolldown.plugins.push([plugin, options])
  return rolldown
}

// usage

// { name: 'my-awesome-plugin', transform: (code, id) => {} }
rolldown.plugin(Object)

 // e.g. buble
rolldown.plugin(Function)

// e.g. buble, { target: { node: '4' } }
rolldown.plugin(Function, Object)

// e.g. 'buble'
rolldown.plugin(String)

// e.g. 'buble', { target: { node: '4' } }
rolldown.plugin(String, Object)

rolldown.transform('some source code', {
  plugins: [
    'commonjs',
    ['node-resolve', { jsnext: true }],
    ['buble', { target: { node: '4' } }]
  ]
}).then(({ code, map }) => {})
tunnckoCore commented 7 years ago

So couple of things to note: