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

Allowing import Id customization #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VeekeeFr
Copy link

@VeekeeFr VeekeeFr commented Jan 6, 2024

Hello @yejimeiming

While converting my project packager to Vite, I encountered some issues with a CJS dependency declaring its imports with "/node_modules/..."

Example : require("/node_modules/react")

Even with your plugin, it causes some issues and I couldn't find any other options or solutions (like aliases...) other than customizing your plugin.

This MR adds a "namingRules" advanced option (function), allowing to customize any detected import to a proper value).

I hope you'll find it useful/usable and include it in your plugin.

Feel free to contact me ²for any information

PS : Sorry if my TS code is imperfect (I'm used to JS :D )

@yejimeiming
Copy link
Member

Hey! 👋
Did someone intentionally write require('react') as require('/node_modules/react') ?
Additionally, the following code can works in Vite now. 👀

require('/node_modules/react')
// ↓↓↓↓ convert ↓↓↓↓
import '/node_modules/react'

@VeekeeFr
Copy link
Author

VeekeeFr commented Jan 8, 2024

Hello 👋

Yep, in a project dependency I have no control of :(

My project architecture is not that simple :

Dependency Project A (module with 'node_modules/react')
// ↓↓↓↓ dependency ↓↓↓↓
Dependency Project B (module => migrated to Vite)
// ↓↓↓↓ dependency ↓↓↓↓
Project C (using Webpack)

Without the patch :

Project C is able to load/work with 'node_modules/react' (webpack / conf magic ?)

Project B can only be started/tested via StoryBook. In that environnement, StoryBook fails to load "node_modules/react".
That may be caused by a Storybook default Vite settings, though I tried to remove them one by one but couldn't find the culprit.

I found easier to work with your plugin :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants