How to handle angular module dependencies in other directories?

Let's say that I have a main module:

angular.module('myApp', ['myApp.view1']);

And another module

angular.module('myApp.view1', ['ngRoute']) 

the second is in a different project directory. The first module cannot find its dependency only if I also add

<script src="view1/view1.js"></script> in the index.html

but it quickly becomes quite difficult to manage manually if it has a lot of javascript files. What is the best way to manage dependencies between angular modules so that they can recognize each other?

+4
source share
2 answers

, grunt gulp javascript index.html. gulp gulp, JS gulp -concat.

gulpfile.js

var gulp = require("gulp");
var concat = require("gulp-concat");

//if all your source js files are inside the src directory
var srcJs = ["src/**/*.js"];

gulp.task("js", function() {
    return gulp.src(srcJs)
               .pipe(concat("app.js") // concat into 1 file called app.js
               .pipe(gulp.dest("dist"); //save app.js in dist directory
});

, gulpfile.js , , "gulp js". js- JS app.js dist. index.html dist/app.js.

+4

, script. javascript .

+2

Source: https://habr.com/ru/post/1584802/


All Articles