laynezh / vite-plugin-lib-assets

A Vite Plugin extracts resource files referenced in library mode instead of embedded them as base64.
MIT License
102 stars 9 forks source link

tsup kills import.meta.url in cjs build #31

Closed Ambroos closed 1 year ago

Ambroos commented 1 year ago

Hi!

In my project setup I was temporarily using an older module system that ended up using CommonJS imports in my Vite config. The CommonJS build of this plugin seems to be broken since v0.5.4, because of the addition of this line in compiler.ts:

const _require = createRequire(import.meta.url)

import.meta gets replaced by an empty object, which makes the url undefined, and createRequire throws.

You may be able to fix this with some simple tsup config: https://tsup.egoist.dev/#inject-cjs-and-esm-shims

I worked around it by fixing my TypeScript config so I would not use the cjs import, but I think it's still worth fixing.

coder-layne commented 1 year ago

Thank you for your feedback, I'll fixed this problem soon.

coder-layne commented 1 year ago

I've just released v0.5.6-beta.0. I hope this resolves the issue you encountered.

Ambroos commented 1 year ago

Looks good now, thanks for taking this on so fast!

coder-layne commented 1 year ago

Looks good now, thanks for taking this on so fast!

It's benifit from the accurate information you provide.