rollup / plugins

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

feat(alias): add warning to avoid unintended duplicate modules #1634

Closed sapphi-red closed 10 months ago

sapphi-red commented 10 months ago

Rollup Plugin Name: alias

This PR contains:

Are tests included?

Breaking Changes?

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

resolves https://github.com/rollup/rollup/issues/5250

Description

When the alias plugin is configured like this

// rollup.config.js
alias({ entries: { $: 'src' } })

and there a file like

import { test as test1 } from './sub.js';
import { test as test2 } from '$/sub.js';

console.log(test1);
console.log(test2);

https://stackblitz.com/edit/rollup-repro-s5tmli?file=src%2Fmain.js

then, import './sub.js' and import '$/sub.js' resolves to different module. (The same file is included in the bundle twice.) I believe this is not what people expect. Also IMO the fact that "import 'src/sub.js' doesn't work but $/sub.js works" is difficult to understand.

This PR adds a warning to catch these cases.

The warning will be shown for those that is using the alias plugin to duplicate the module, but I guess no one would do that. It'd be easier to create a different plugin in that case.