Dan
Dan

Reputation: 3459

Using browserify in large projects

I'm not clear on how I should breakdown my code for large projects when using browserify. For instance, if I have a login page, signup page, dashboard, etc - do I require all of those modules in my main.js? And if so, what's the best practice for ensuring that modules that should only be run on the login page aren't run on other pages? Are there any good examples of how to breakdown larger projects when using browserify?

Upvotes: 0

Views: 359

Answers (1)

Ian Lim
Ian Lim

Reputation: 4284

One possible example is to use browserify to compile two js files:

  • 1) One js file contains commonly used codes shared by the various pages
  • 2) One js files contains specific codes used by that particular page

In the html just include the two files accordingly:

<html>
<header>
</header>
<body>
   <!-- Common js libraries/modules used across a couple of pages -->
   <script type="text/javascript" src="js/common_libraries.js"></script>
   <!-- Page specific js file -->
   <script type="text/javascript" src="js/modules_specific_to_this_page.js"></script>
</body>
</html>

Upvotes: 1

Related Questions