2

Edit: I want to emphasize that i dont know what is the proper solution or how to treat this situation .. im looking for answer how to manage it , and where do i need to load all of the files.

After Implementing this type of folder structure , i got some problem with extra javascript files , i dont know how should i need to make them work , in the usual way for every js file , i would add :

 <script type="text/javascript" src="script.js"></script>
 <script type="text/javascript" src="script2.js"></script>

..

to

<script type="text/javascript" src="script50.js"></script>

so lets assume that i have 50 javascripts files , do i need to link them all in the index.html page ? so i will have those line 50 times? it doesnt seem reasonable.

maybe i dont get this apporach can someone make it clear for me.

example of folder structure:

example of folder structure

so where do i need to "load" the scripts in the index.html ? maybe to gather them all into one file(like minify)?

Elad Israeli
  • 131
  • 2
  • 11
  • What's your coding environment? In .NET, you can use Bundling to combine (and minify) all the files in a directory. In other situations, you have other options. – Dave Feb 16 '16 at 18:19
  • Possible duplication of [http://stackoverflow.com/questions/14460231/how-do-you-import-multiple-javascript-files-in-html-index-file-without-the-bloat](http://stackoverflow.com/questions/14460231/how-do-you-import-multiple-javascript-files-in-html-index-file-without-the-bloat) – Liadco Feb 16 '16 at 18:26

2 Answers2

1

If you use some build system you can use concat.

e.x for gulpjs https://www.npmjs.com/package/gulp-concat

oto lolua
  • 499
  • 4
  • 16
  • This is more of a comment than an answer. Could you expand it and include the philosophical reasons behind using a build system for angular? –  Feb 16 '16 at 18:07
  • there is still no explantion who do i need to treat this situation , do i need to gather all into one file? or have alot of links to the scripts as i mentioned ? – Elad Israeli Feb 16 '16 at 18:08
0

Look into Webpack - it's a little convoluted to set up initially (Pete Hunt's how-to might help), but as far as module bundling tools go it's probably one of the most powerful.

Joe Clay
  • 33,401
  • 4
  • 85
  • 85
  • there is still no explantion who do i need to treat this situation , do i need to gather all into one file? or have alot of links to the scripts as i mentioned ? – Elad Israeli Feb 16 '16 at 18:08
  • I definitely wouldn't recommend adding a script tag for every single file of your app - a) it's a pain in the butt to maintain as your project grows, and b) it usually means all your code is going into the global scope of the window. Tools like Webpack and Browserify solve this by allowing you to use Node.js style `require` statements to define each file's dependencies, and then bundle everything up into a single file. Additionally, with some extra tweaking you can use it bundle up HTML, CSS, images, etc. – Joe Clay Feb 16 '16 at 18:30
  • For example, my project's Webpack config bundles up 100+ files into an `app.js` file and a `vendor.js` file - those are what I include in my HTML page. – Joe Clay Feb 16 '16 at 18:31
  • well in my last question i was offered to do it and i did implement this but in this situation i implemneted in on mini project that have only 1 file with class(in es6) called polygon , and another js file whom import this class and use it as well .. but in my another project it kinda bigger app , that have alot of files that are configure the controllers , services etc. i want it to "work" and i see the only way is to include it , in the line script. http://stackoverflow.com/a/35058750/5623124 this is the link to the answer i implemneted . i hope you understand my understanding problem – Elad Israeli Feb 16 '16 at 18:38