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

How to know which file(s) were entry points? #225

Closed
leeola opened this issue Oct 8, 2012 · 4 comments
Closed

How to know which file(s) were entry points? #225

leeola opened this issue Oct 8, 2012 · 4 comments

Comments

@leeola
Copy link

leeola commented Oct 8, 2012

In Node.js you can use require.main to know when a file was executed directly. Is something like this possible with Browserify?

It appears require doesn't even exist during runtime (i assume it's parsed during compile), so is there any way to make a file know if it was the entry point?

Eg: if require.main == module { // do stuff }

@EndangeredMassa
Copy link

Can you provide an example of why you would need to know that in a module?

@leeola
Copy link
Author

leeola commented Oct 31, 2012

For the same reasons you might need that in normal Node.

Importing a file and executing a file are usually considered two distinct actions. So with Browserify not being able to specify this, you are left with a void.. Was this entry-file imported? As it might be during tests/etc, or was this file run directly.

I consider a module that "does something" when imported to be rather volatile. Browserify forces this onto you (i believe), so i feel compelled to isolate this file.

@ghost
Copy link

ghost commented Feb 22, 2013

Files that execute directly with side-effects are probably a good thing to isolate from modules that export functionality explicitly. This feature does not fit very well with the v2 changes either.

@ghost ghost closed this as completed Feb 22, 2013
@leeola
Copy link
Author

leeola commented Feb 25, 2013

Files that execute directly with side-effects are probably a good thing to isolate from modules that export functionality explicitly.

I would like to not have them at all. There is no need for it in Node, why have a need for it in Browserify?

This feature does not fit very well with the v2 changes either.

Ah, oh well. Thanks for responding :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants