使用gulp来连接angularjs文件,但得到[$ injector:modulerr]

时间:2017-07-04 10:02:07

标签: angularjs gulp

首先,我将每个angularjs文件导入到html中,并且工作正常 但是,我想使用gulp将这些文件连接到一个文件中以减少连接量 我的文件夹结构是:

--- public
 |- app.js
 |- controller.js
 |- directives.js
 |- factories.js
 |- filter.js
 |---
    |--- events
       |- app.js
       |- controller.js
    ....

在我的/public/app.js中,我声明了路由器

$stateProvider
    .state('events', {
         url: "/",
         templateUrl: "/public/partial/events",
         controller: "events",
         reloadOnSearch: false
    }).....

我将每个页面声明为一个文件夹,例如事件,并包含app.js和controller.js。

我的活动/ app.js是

angular.module('events', ['ui.router', 'ngRoute', 'events.controller'])
    .config(['$routeProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider',
        function($routeProvider, $locationProvider, $stateProvider, $urlRouterProvider) {

        }
    ]);

events / controller.js是

angular.module('events.controller', ['restangular', 'LocalStorageModule', 'oitozero.ngSweetAlert', 'Alertify', 'daterangepicker', 'ngTable', 'slick'])
    .controller('events', ['$scope','$compile', ....,
        function ($scope, $compile, ....) {

我的gulpfile.js只是简单地连接所有angularjs文件但是出错了!

gulp.src([
        "/public/app-v8.js",
        "/public/controller-v22.js",
        "/public/directives-v6.js",
        "/public/factories-v5.js",
        "/public/filters-v1.js",
        "/public/events/app-v0.js",
        "/public/events/controller-v23.js",
       .....
    ])

1 个答案:

答案 0 :(得分:0)

在你的gulpfile中,giv

var gulp = require('gulp');
var concat = require('gulp-concat');
var minify = require('gulp-minify');
var cleanCss = require('gulp-clean-css');

    gulp.task('pack-js',function(){
        return gulp.src(['app.js',
            'common/controllers.js',
            'common/services.js',
            ....
            ])
        .pipe(concat('bundle.js'))
        .pipe(minify())
        .pipe(gulp.dest('myFolder/build/js/'))
});

'bundle.js' contain all your JS files. Similarly you can do for CSS files also.

At last you can run your task like this.

gulp.task('bundle-assets',['pack-js','pack-css']);