2017-02-27 7 views
2

js 파일을 uglify하려고합니다. index.html 번들 파일을 사용할 때. 나는 아래의 오류가 발생합니다.

다음은 내 gulp 파일입니다.

'use-strict' 
var gulp = require('gulp'); 
var uglify = require('gulp-uglify'); 
var concat = require('gulp-concat'); 
var exec = require('gulp-exec'); 
var ngAnnotate = require('gulp-ng-annotate'); 
const babel = require('gulp-babel'); 
var exec = require('child_process').exec; 
gulp.task('scripts', function() { 
return gulp.src(['vzrth.js','psrhs.js']) 
.pipe(ngAnnotate()) 
    .pipe(babel({ 
     presets: ['es2015'] 
    })) 
    .pipe(concat('bundle.js')) 
    .pipe(uglify().on('error', function (e) { 
     console.log(e); 
    })) 
    .pipe(gulp.dest('./client')); 
}); 
gulp.task('nodestart', function (cb) { 
    exec('node ./bin/www', function (err, stdout, stderr) { 
    console.log(stdout); 
    console.log(stderr); 
    cb(err); 
    }); 
}) 
gulp.task('default', ['scripts', 'nodestart']); 

내가 오류는 다음과 같습니다

reference error: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.8/ $injector/modulerr?p0=e

+0

무엇을 depen 특수 효과 주석을 사용하고 있습니까? 암시 적 주석을 사용하는 경우 축소하는 동안 서비스 이름의 이름이 변경되어 앱이 중단됩니다. – Und3rTow

+0

컨트롤러 또는 지침 중 하나의 예제를 제공 할 수 있습니까? –

+0

아래에 – user7353226

답변

6

당신이 잘못 할 경우 의존성 주입 (DI)가 중단된다는 점에 유의해야 할 각 파일을 작게를합니다.

.controller('MyController', ['$scope', '$timeout', function ($scope, $timeout) { 
    $scope.title = 'Minify me'; 
}); 

이유는 무엇입니까 첫 번째 예제 휴식 :

.controller('MyController', function($scope, $timeout) { 
    $scope.title = 'Minify me'; 
}); 

이것은 DI와 동일한 컨트롤러의 축소를 SAFE 예입니다

이는 DI와 컨트롤러의 축소를 안전하지 않은 예입니다 때 축소?

당신은 축소에 후 함수에서 매개 변수가 그래서 이것은 컨트롤러 것이 더 간단 뭔가 축소 된 얻을 자바 스크립트 파일을 작게를 할 때 : 첫째에게 안전하지 않은 예 :

.controller('MyController', function(a, b) { 
    a.title = 'Minify me'; 
}); 

당신이 볼 수 있듯이, 을 범위으로 축소했습니다. 은 Angular에 아무런 의미가 없습니다. 실제로 서비스가 으로 정의 된 경우가 아니면 예외입니다. 이제 작게하다 안전 예

:이 예에서는

.controller('MyController', ['$scope', '$timeout', function (a, b) { 
     a.title = 'Minify me'; 
    }); 

각도는 리터럴 문자열이 축소 된되지 않기 때문에 첫 번째 매개 변수가 실제로 $ 범위 것을 알고있다.

편집 :이 같은 컨트롤러 또는 지시를 선언하면

가 (안전하지 않은 축소하세요) :

.controller('MyController', controller); 
function controller($scope, $timeout) { 
    $scope.title = 'Minify me' 
} 

이 될 것 (방법 1) :

.controller('MyController', controller); 
controller.$inject = ['$scope', '$timeout']; 
function controller($scope, $timeout) { 
    $scope.title = 'Minify me' 
} 

또는이 될 것입니다 (방법 2)

.controller('MyController', ['$scope','$timeout', controller]); 
function controller($scope, $timeout) { 
    $scope.title = 'Minify me' 
} 
+0

의 'use strict'를 입력했습니다. 컨트롤러 ''headerController ', [$ location', '$ window', '$ stateParams', '$ log', 'HeaderFactory', 'UserDataService', angular.module ('HeaderCtrl', []) 함수 ($ location, $ window, $ stateParams, $ log, headerFactory, userDataService) { var vm = this; VM.프로필 = []; // 사용자 프로필 세부 배열 function init() { }; init(); } ] ); 위의 – user7353226

+0

은 내 컨트롤러 코드의 형식입니다. – user7353226

+0

제공 한 컨트롤러가 소형화를 위해 완전히 안전 해 보입니다. 다른 컨트롤러에서 실수하지 않았습니까? [엄격한 DI 모드] (https://docs.angularjs.org/guide/production)를 활성화 해보십시오. –