rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.57k stars 568 forks source link

Watch mode: multiple saves required for changes to be transpiled correctly #1689

Closed manuel3108 closed 3 months ago

manuel3108 commented 4 months ago

Expected Behavior

Because the reproduction is using a monorepo to visualize the problem, the repo is using PNPM, please excuse this.

Saving a file once, should lead to a rebuild that contains all changes made up until the last save by the developer.

Actual Behavior

After the initial build and the first rebuild after a save, it's required to save your file two times that build output is updated.

https://github.com/rollup/plugins/assets/30698007/2fe2e7d0-4a71-416a-9fb0-d13c11580c63

Additional Information

The repo has two projects @project/tools which depends on @project/core. Both projects are linked vie NPM dependencies. Both projects contain only the bare minimum code for reproduction.

After a lot of trying around, I was able to find out that the @rollup/plugin-node-resolve is causing this problem. Once you comment that plugin out in the rollup config, or add the line described below, the error disappears.

nodeResolve({
    resolveOnly: (module) => !module.includes('@project'),
}),

But adding that line has the side-effect that my internal dependencies are not bundled into the output anymore, which is something I really would like to have.

manuel3108 commented 3 months ago

Looks like I had some misunderstanding about how the project should be setup. I initially did not use rollup and used the tsc compiler. That's why I had tsconfig.json files flying around everywhere, while using the composite and outDir settings everywhere.

The key is to remove all those unnecessary tsconfig.json and only keep the one in the root. No composite or outDir settings should be set there. Then inside the rollup.config.js you can pass the outDir directly to the rollup plugin. These changes made everything work flawlessly.