kidonng / unocss-preset-daisy

UnoCSS preset for daisyUI
https://unocss-preset-daisy.vercel.app
MIT License
220 stars 19 forks source link

[Feature Quest]: CommonJS build #33

Open yuche opened 8 months ago

yuche commented 8 months ago

In some cases, vite is running in commonjs and developers are not authorised to change it. eg. Same CodeSandbox container. This can cause an error to be reported:

Error [ERR_REQUIRE_ESM]: require() of ES Module /project/sandbox/node_modules/unocss-preset-daisy/index.js from /project/sandbox/vite.config.ts not supported.

unocss-preset-daisy should provided a CommonJS build and specify the values of import and require in packages.json#exports like this.

kidonng commented 8 months ago

When this first got popular, I released a dual package version, but later went back to ESM only as I don't see why projects can't use ESM when they are new enough to deploy UnoCSS. It's like rejecting const foo = 'bar' while using Array.prototype.at.

As for your case, I doubt CodeSandbox, being a fairly popular service, doesn't support ESM. It's more like a config mistake. Could you provide a reproducible link?

yuche commented 8 months ago

When this first got popular, I released a dual package version, but later went back to ESM only as I don't see why projects can't use ESM when they are new enough to deploy UnoCSS. It's like rejecting const foo = 'bar' while using Array.prototype.at.

As for your case, I doubt CodeSandbox, being a fairly popular service, doesn't support ESM. It's more like a config mistake. Could you provide a reproducible link?

Repro:

Note that changing vite.config.js or vite.config.ts to vite.config.mjs seems to work, but in reality it will only work within CodeSandbox website itself, not if you use sandpack.

lzdml commented 6 months ago

you can use import 'daisyui/dist/full.css'; in main.ts

yuche commented 6 months ago

you can use import 'daisyui/dist/full.css'; in main.ts

Yes I can do that. But the reason for using this plugin is that I want the packaged files to be as small as possible, otherwise why would I use vite?