rollup / plugins

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

Recommend consistent order for commonjs and node-resolve plugins #1752

Open Krinkle opened 3 months ago

Krinkle commented 3 months ago

Documentation Is: Confusing.

Please Explain in Detail...

import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
…
plugins: [nodeResolve(), commonjs()]

Vs

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
…
  plugins: [commonjs(), resolve()]

As an inexperienced user of Rollup, the difference is distracting and giving me reason to be uncertain, thinking that perhaps one of them is wrong or that I'll expose myself to some subtle bug if I do it wrong, or worse, that both are right for different use cases (hoping that's not the case!).

Your Proposal for Changes

If both behave the same, pick one and recommend it the same way in both. If one has issues, pick the other one. If both have merit, pick the same one to recommend by default in both packages, and document why/when to deviate.

smartrejames commented 1 week ago

When using these two plugins, @rollup/node-resolve should typically be placed before @rollup/commonjs in the plugin list. This is because the node-resolve plugin primarily helps Rollup locate and bundle modules from node_modules, while the commonjs plugin is used to convert CommonJS modules into ES6 modules.

Placing node-resolve first ensures that all module paths are correctly resolved before converting CommonJS modules. This order can often prevent issues related to unresolved paths when handling certain modules. Therefore, the recommended plugin order is:

This sequence helps ensure that the modules used in your project can be correctly resolved and transformed.