zont / gulp-usemin

MIT License
338 stars 92 forks source link

Usemin + NgAnnotate not working #59

Closed futurechan closed 9 years ago

futurechan commented 10 years ago

I am trying to use gulp-ng-annotate with gulp-usemin. I get concatenated .js files, but they have not been uglified or min-safed with ngAnnotate.

Here's my task config

var gulp = require('gulp')
    , concat = require('gulp-concat')
    , uglify = require('gulp-uglify')
    , usemin = require('gulp-usemin')
    , minifyHtml = require('gulp-minify-html')
    , minifyCss = require('gulp-minify-css')
    , less = require('gulp-less')
    , ngAnnotate = require('gulp-ng-annotate')
;

gulp.task('usemin', ['install-client'], function() {
    gulp.src('./src/client/index.html')
        .pipe(usemin({  
            remove:[],
            less: [less(), minifyCss(), 'concat'], 
            js: [ngAnnotate(), uglify(), 'concat']
        }))
        .pipe(gulp.dest('build/client'));
});
avandendaele commented 10 years ago

I'm new with Gulp but I could set up an very simple AngularJS project with ngAnnotate + uglify + usemin. I have the expected result: scripts got annotated then uglified and concatenated. Your files get only concatenated maybe because your pipelineId is not correct. According to the documentation, if pipelineId is not found files get only concatenated. Here is a part of my html

<!-- build:js -->
... some script tags here ...
<!-- endbuild -->

Here is the usemin part of my gulpfile.js

.pipe(usemin({
  js: [ngAnnotate(ngOpts), uglify(), 'concat'],
  ... other pipelineIds ...
})
b-long commented 10 years ago

Could both of you provide your package.json file so that I know what versions you're using?

futurechan commented 10 years ago

I did get it working. I consolidated my build:js blocks into one and it worked.

{
    "name": "Core-Site",
    "version": "0.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "license": "Commercial",
    "dependencies": {
         "body-parser": "^1.6.3",
    "connect-memcached": "^0.1.0",
    "cookie-parser": "^1.3.2",
    "elasticsearch": "^2.4.0",
    "express": "^4.8.3",
    "express-session": "^1.7.5",
    "method-override": "^2.1.3",
    "nconf": "^0.6.9",
    "needle": "^0.7.8",
    "passport": "^0.2.0",
    "passport-windowsauth": "^0.2.0",
    "qs": "^2.1.0",
    "rabbit.js": "^0.4.1"
    },
  "devDependencies": {
    "chai": "^1.9.1",
    "chai-as-promised": "^4.1.1",
    "gulp": "^3.8.6",
    "gulp-concat": "^2.3.4",
    "gulp-ignore": "^1.1.0",
    "gulp-install": "^0.2.0",
    "gulp-less": "^1.3.5",
    "gulp-minify-css": "^0.3.7",
    "gulp-minify-html": "^0.1.4",
    "gulp-mocha": "^1.0.0",
    "gulp-ng-annotate": "^0.3.0",
    "gulp-uglify": "^0.3.1",
    "gulp-usemin": "^0.3.8",
    "gulp-watch": "^0.6.8",
    "mocha": "^1.19.0",
    "mocha-teamcity-reporter": "0.0.3",
    "sinon": "^1.10.2",
    "sinon-chai": "^2.5.0",
    "yargs": "^1.2.6"
  }
}
b-long commented 10 years ago

@futurechan Thanks Josh. Are you saying that you consolidated the build:js blocks in your HTML? So you Gulpfile still looks like this basically:

var gulp = require('gulp')
    , concat = require('gulp-concat')
    , uglify = require('gulp-uglify')
    , usemin = require('gulp-usemin')
    , minifyHtml = require('gulp-minify-html')
    , minifyCss = require('gulp-minify-css')
    , less = require('gulp-less')
    , ngAnnotate = require('gulp-ng-annotate')
;

gulp.task('usemin', ['install-client'], function() {
    gulp.src('./src/client/index.html')
        .pipe(usemin({  
            remove:[],
            less: [less(), minifyCss(), 'concat'], 
            js: [ngAnnotate(), uglify(), 'concat']
        }))
        .pipe(gulp.dest('build/client'));
});

Also, has this issue been a problem for you?

futurechan commented 10 years ago

@b-long yes, I consolidated them in my html, and I'm not generating source maps yet.

b-long commented 10 years ago

@futurechan Ah, I see. Ok, thanks for the help!