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

preserveModules creates wrong output #3743

Closed
johannes-z opened this issue Aug 24, 2020 · 6 comments
Closed

preserveModules creates wrong output #3743

johannes-z opened this issue Aug 24, 2020 · 6 comments

Comments

@johannes-z
Copy link
Contributor

johannes-z commented Aug 24, 2020

Expected Behavior

The emitted lib folder should look like this:

  • main.js
  • HelloWorld.vue_rollup-plugin....js
  • HelloWorld.vue.js

Actual Behavior

The emitted lib folder looks like this:

  • node_modules/
  • src
    • HelloWorld.vue_rollup-plugin....js
    • HelloWorld.vue.js
  • main.js

The plugins resolve and commonjs do nothing to remedy this, also adding those libraries added to node_modules to externals does nothing.

Additional

In a monorepo, all the files within lib are also under the path the monorepo is under, i.e. if the package is in /my-project/packages/my-package, the output will look like this. /my-project/packages/my-package/lib/package/my-package/main.js

@lukastaegert
Copy link
Member

The answer is simple: There are several files from node_modules that are included in the build, and preserveModules preserves the directory structure. If you do not want this, or you want some partial bundling, I fear your only option would be to put all files that you want as separate inputs as an array into the input property.

@johannes-z
Copy link
Contributor Author

Shouldn't marking those node_modules as externals be sufficient to not have them copied to the dist folder? I tried a number of ways preventing those node_modules from ending up in my dist folder, but nothing seemed to work. Especially @rollup/plugin-commonjs always messed up the dist folder because it creates a _virtual folder.

@lukastaegert
Copy link
Member

Hmm, I thought ids were passed twice through external, but apparently only unresolved ids are passed here. Will need to check this again. Anyway, if you use a function for external you can log what ids are passed here and add those to external that are needed. In your case

external: ['tslib', 'vue', 'vue-class-component', 'vue-property-decorator', 'vue-runtime-helpers/dist/normalize-component.mjs']

did the trick. Or if you do it via a function

external(id) {
  return id === 'tslib' || id.startsWith('vue');
}

and last via regular expression

external: /^(tslib$|vue)/

@lukastaegert
Copy link
Member

Fix for the external behaviour here: #3753. This was apparently overlooked for quite some time.

@johannes-z
Copy link
Contributor Author

Thanks! Seems to work for me now.

@cimchd
Copy link

cimchd commented Dec 19, 2022

Just in case someone (like me) finds this topic first. In a monorepo it may help to also add preserveModuleRoot option.

See: rollup/plugins#321

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

3 participants