Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can unbuild build code in IIFE format? #372

Closed
1 task
keer-tea opened this issue Feb 22, 2024 · 2 comments
Closed
1 task

Can unbuild build code in IIFE format? #372

keer-tea opened this issue Feb 22, 2024 · 2 comments

Comments

@keer-tea
Copy link

Describe the feature

Can unbuild build code in IIFE format?

I configured it like below but it didn't work as expected.

import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
  entries: [
    'src/index',
  ],
  clean: true,
  declaration: true,
  rollup: {
    output: {
      name: 'Gtool',
      format: 'iife'
    }
  }
})

Additional information

  • Would you be willing to help implement this feature?
@peterroe
Copy link
Contributor

Maybe just rename your bundle name, I guess?

import { renameSync } from 'fs'
import { resolve } from 'path'
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
  entries: [
    'src/index',
  ],
  clean: true,
  rollup: {
    output: {
      name: 'Gtool',
      format: 'iife',
    },
  },
  hooks: {
    'build:done': function ({ options }) {
      renameSync(resolve(options.outDir, 'index.mjs'), resolve(options.outDir, 'index.js'))
    },
  },
})

@keer-tea
Copy link
Author

Haha, thank you. I didn't even look at the built files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants