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

Align require with node's require #4

Closed
jhnns opened this issue Jul 4, 2012 · 3 comments
Closed

Align require with node's require #4

jhnns opened this issue Jul 4, 2012 · 3 comments

Comments

@jhnns
Copy link
Member

jhnns commented Jul 4, 2012

For compatibility reasons modules-webpack's require should provide the same API as node's require. Especially the cache-object can be very useful (e.g. for unit tests).

@jhnns
Copy link
Member Author

jhnns commented Jul 4, 2012

I'm not quite sure about require.resolve() but you could resolve the path while bundling and replace the relative path within the brackets with the (sanitized) absolute path (like you're doing it with require) (#5). The resolve function in the browser is a simple pass-through function that returns the passed path. This way I could easily remove a module from cache.

Imagine this code:

var modulePath = require.resolve("myModule/lib/test.js");

delete require.cache[modulePath];

@sokra
Copy link
Member

sokra commented Jul 4, 2012

I think the most useful thing is to return the "id" (a number) from require.resolve because it's the only thing the browser should know. require.cache uses the module number as key.

While compiling I replace the require.resolve call with a module id and the already existing cache object is exposed as require.cache.

@sokra sokra closed this as completed in 3b219e3 Jul 4, 2012
@sokra
Copy link
Member

sokra commented Jul 4, 2012

done

connorjclark pushed a commit to connorjclark/webpack that referenced this issue Jan 28, 2018
Update binCases/statsCases after merge from origin
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

2 participants