kadikraman / draftjs-md-converter

Converts content from Draft.js blocks to Markdown and vice versa.
https://kadikraman.github.io/draftjs-md-converter/
MIT License
145 stars 37 forks source link

Switch to esbuild from parcel-bundler #71

Closed nikolaik closed 3 years ago

nikolaik commented 3 years ago

Hi there 👋 Please let me know if any of these changes are unwanted or not working as intended.

kadikraman commented 3 years ago

Hi @nikolaik thanks so much for the PR! Definitely happy to add this.

There's a bit of an issue with the current script though, it looks like only the last last output of esbuild.build is kept. It's async I think so maybe a race condition? As a result running yarn compile will only have the .esm.js files in the /dist folder.

I've never used esbuild before so not sure on the best practices. Moving the second esbuild.build into a .then block will create all 4 files (though there's probably a nicer way to do this):

esbuild
  .build(
    Object.assign(options, {
      outfile: pkg.main,
      format: 'cjs'
    })
  )
  .then(() => {
    esbuild
      .build(
        Object.assign(options, {
          outfile: pkg.module,
          format: 'esm'
        })
      )
      .catch(() => process.exit(1));
  })
  .catch(() => process.exit(1));
nikolaik commented 3 years ago

Hi @nikolaik thanks so much for the PR! Definitely happy to add this.

Swell!

There's a bit of an issue with the current script though, it looks like only the last last output of esbuild.build is kept. It's async I think so maybe a race condition? As a result running yarn compile will only have the .esm.js files in the /dist folder.

I've never used esbuild before so not sure on the best practices. Moving the second esbuild.build into a .then block will create all 4 files (though there's probably a nicer way to do this):

I'm pretty new to esbuild myself, but found this pattern of doing it in another repository somewhere. Pushed a fix now using two await's which seems to fix things.

(async () => {
  await esbuild
    .build({ ...options, outfile: pkg.main, format: 'cjs' })
    .catch(() => process.exit(1));

  await esbuild
    .build({ ...options, outfile: pkg.module, format: 'esm' })
    .catch(() => process.exit(1));
})();

Bonus: Switched to destructuring syntax from Object.assign

kadikraman commented 3 years ago

Released in v1.5.0 🚀