unjs / unbuild

📦 A unified JavaScript build system
MIT License
2.36k stars 91 forks source link

Config for esbuild target #19

Closed harlan-zw closed 2 years ago

harlan-zw commented 3 years ago

The current rollup build targets es2020 explicitly, which is good for most use cases. However, I had an issue where node 12.x support was needed on a build.

Happy to attempt a PR for it, just was a bit unsure of the best way to go about that with keeping the abstract nature of the build.

pi0 commented 3 years ago

Supporting target option per-entry seems a nice idea!

harlan-zw commented 2 years ago

I needed this to change all entries, it looks like you can use the esbuild.target config key to accomplish that.

If anyone else needs this, see:


export default defineBuildConfig({
  declaration: true,
  rollup: {
    emitCJS: true,
    cjsBridge: true,
    esbuild: {
      target: 'es2019'
    }
  },
  clean: true,
  entries: [
    'src/plugin',
    // loaders aren't part of the plugin entry
    { input: 'src/loaders/dev-tools', name: 'loaders/dev-tools', declaration: false, format: 'cjs', ext: 'cjs'  },
    { input: 'src/loaders/virtual-module', name: 'loaders/virtual-module', declaration: false, format: 'cjs', ext: 'cjs'  },
    { input: 'src/loaders/windicss-css', name: 'loaders/windicss-css', declaration: false, format: 'cjs', ext: 'cjs' },
    { input: 'src/loaders/windicss-style-pitcher', name: 'loaders/windicss-style-pitcher', declaration: false, format: 'cjs', ext: 'cjs' },
    { input: 'src/loaders/windicss-template', name: 'loaders/windicss-template', declaration: false, format: 'cjs', ext: 'cjs'  },
  ],
  externals: [
    'webpack',
  ],
})

Better support for per-entry configurations seems like it would be its own feature so I'll close this off