3

I have written a angular application (MEAN) using nodejs in back-end. There are multiple modules in the application so have multiple controller.

We have to include all the controllers in the index.html file and new one as well if we added in any module.

I have checked the other application which are running on the same stack (MEAN) but in there source code i haven't found all the controllers.

So please help me around the same to optimize my application.

2
  • Do you mean something like including only one src file for the javascript? Commented Oct 21, 2016 at 9:46
  • @Katana24 : Yes buddy, I just want to include one js file in index.html Commented Oct 21, 2016 at 11:24

1 Answer 1

1

Well then I'd suggest looking into Gulp as it allows you to concatenate and, if you want to, minify your codebase and place it into one file. That single file can then be referenced in your index.html

// Example - Concate the js files together and place them in the dist folder
gulp.task('js', function(){
  var src = ['../../file-name.js'];
  return gulp.src(src)
    .pipe(concat('main.js').on('error', gutil.log))
    .pipe(gulp.dest('dist/js').on('error', gutil.log))
});

This is an example of what I used when I worked with Angular1. Gulp places all my target files into the dist folder and into the main.js file which I reference in the index.html file.

 <script type="text/javascript" src="js/main.js"></script>
Sign up to request clarification or add additional context in comments.

2 Comments

@RISHABHBANSAL Great - did you encounter any other problems related to this? If it worked for you then accept the answer and upvote - if not then elaborate on what did work
Its worked for me without any problem and i already up-voted for the same since i am new user that's why its not showing publicly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.