Ephem / rollup-plugin-preserve-directives

A Rollup plugin to preserve directives like "use client" when preserveModules is true
MIT License
67 stars 8 forks source link

packages builds are getting generated in dist/node_modules directory #24

Closed imtheaman closed 4 months ago

imtheaman commented 8 months ago

I don' think it's a good idea to set output.preserveModules option to true, ain' there a workaround to this? my dist directory looks like this

_virtual/
node_modules/
src/
base.js
index.d.ts
index.js
tailwind.config.js
Ephem commented 8 months ago

So, most directives work at the top of files, and they are scoped to that file. If you bundle your code into one file, and some of those files are for example React client components, should this plugin:

A) Include the "use client" at the top of the bundle making all components client components? B) Ignore it and make no components client components?

Another approach could be to split the bundle into two, so everything with "use client" ends up in one and everything else ends up in the other, but that's out of scope for this plugin which aims to be agnostic around which directives are preserved. The idea with preserveModules is that it delays bundling to the consuming application, meaning, it keeps all files intact and lets whoever uses your library deal with composing them together into bundles which makes sense.

Does that explanation make sense?