ericclemmons / grunt-angular-templates

Grunt build task to concatenate & pre-load your AngularJS templates
MIT License
711 stars 108 forks source link

Unable to use with usemin and no uglify step #129

Open agliznetsov opened 9 years ago

agliznetsov commented 9 years ago

I'm using yeoman angular project template but my usemin task has no uglify step, only concat.

Here's my config: ngtemplates: { dist: { cwd: 'app', src: 'views/{,/}.html', dest: '.tmp/templateCache.js', options: { module: 'myApp', usemin: 'scripts/app.js' } } }, During the build the generated templateCache.js is not added to the app.js and I see this error message: Usemin has not created uglify.generated yet!

When I changed the config to this: options: { module: 'myApp', concat: 'generated', } it works but templateCache gets added to both app.js and vendor.js.

Hendler commented 8 years ago

+1

maybe it's expected? http://stackoverflow.com/questions/32147356/no-views-present-in-dist-when-building-with-grunt

fvanwijk commented 8 years ago

I have the same. It gives the error:

Usemin has not created uglify.generated yet!

It looks like you have to concat the templates yourself in the concatted (non-uglified) output, but it will make usemin pretty useless.

achyutjhunjhunwala commented 8 years ago

Well same issue, i have register 2 tasks, 1 for development purpose 1 for deployment. For the development one, i have removed the uglify from usemin.

But now ngTemplate is expecting uglify:generated. ngAnnotate should not expect for usemin dependencies so strictly

mhawila commented 8 years ago

@fvanwijk What did you about this? I am facing the same issue.

--Update-- I removed node_modules directory and rerun npm install. It worked. So weirdo though!!

fvanwijk commented 8 years ago

@mhawila It seems that grunt-angular-template and especially grunt-usemin (unmaintained) is really an all-or-nothing solution. Custom configuration still has a lot of quirks.

I only do concat and ngtemplates with usemin. The buildjs annotations in index.html already contain xxx.min.js. Since the uglify task is not related to prepareUsemin anymore, it has its own config. I also concat the templateCache manually with an extra step.

Eventually I want to get rid of Grunt build tasks such as usemin, since ES6 modules with eg. Webpack give a lot more configuration freedom and a better project structure. I see usemin as a deprecated solution.

Note that when you use Webpack, you load bundle.js in a script tag in both development and production template, so there is no need voor template rewriting using grunt-angular-templates anymore.

For completeness, this is my config, cleaned up for readibility, hope it still works for you:

{
  concat: {
    templates: {
      files: {
        'dist/scripts/scripts.min.js': [paths.dist + '/scripts/scripts.min.js', '.tmp/scripts/templateCache.js'],
      }
    }
  },
  cssmin: {
    dist: {
      files: [{
        expand: true,
        cwd: paths.dist + '/styles',
        src: '**/*.css',
        dest: paths.dist + '/styles'
      }]
    }
  },
  htmlmin: {
    dist: {
      files: [{
        expand: true,
        cwd: paths.app,
        src: ['*.html'],
        dest: paths.dist
      }]
    }
  },
  ngtemplates: {
    dist: {
      files: [{
        cwd: '.tmp/app',
        src: 'scripts/**/*.html',
        dest: '.tmp/scripts/templateCache.js'
      }]
    }
  },
  uglify: {
    dist: {
      files: [{
        expand: true,
        cwd: paths.dist + '/scripts',
        src: '*.js',
        dest: paths.dist + '/scripts'
      }]
    }
  },
  usemin: {
    html: [paths.dist + '/**/*.html'],
    options: {
      dirs: [paths.dist + '']
    }
  },
  useminPrepare: {
    dist: [paths.app + '/*.html'],
    options: {
      dest: paths.dist,
      flow: {
        steps: {
          // Do not run 'cssmin' and 'uglify'. We do it separately for non-lib css/js files
          js: ['concat'],
          css: ['concat']
        }
      }
    }
  }
},

Build task:

grunt.registerTask('build', [
    'useminPrepare',
    'concat:generated',

    // Must run after concat:generated but before rev. See https://github.com/ericclemmons/grunt-angular-templates/issues/129
    'ngtemplates',
    'concat:templates',

    'rev',
    'htmlmin',
    'usemin',
    'cssmin',
    'uglify'
  ]);
alexey-sh commented 4 years ago

it seems like there is no way to avoid "uglify:generated"