Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

'grunt cdnify' doesn't do anything #266

Closed
bsphere opened this issue Jul 3, 2013 · 33 comments
Closed

'grunt cdnify' doesn't do anything #266

bsphere opened this issue Jul 3, 2013 · 33 comments

Comments

@bsphere
Copy link

bsphere commented Jul 3, 2013

'grunt build' results are the local files rather than Google CDN,

this build process does output:

Running "cdnify:dist" (cdnify) task
Going through dist/404.html, dist/index.html to update script refs

but still all scripts point to bower_components/

index.html:

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet" href="styles/7d151330.main.css">
</head>
  <body ng-app="testApp">
    <!--[if lt IE 7]>
      <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
    <![endif]-->

    <!--[if lt IE 9]>
      <script src="bower_components/es5-shim/es5-shim.js"></script>
      <script src="bower_components/json3/lib/json3.min.js"></script>
    <![endif]-->

    <!-- Add your site or application content here -->
    <div class="container" ng-view=""></div>

    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
    <script>
      var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
      (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
      g.src='//www.google-analytics.com/ga.js';
      s.parentNode.insertBefore(g,s)}(document,'script'));
    </script>

    <script src="bower_components/angular/angular.js"></script>

    <script src="scripts/4355b290.scripts.js"></script>

        <script src="scripts/bd6ce9e3.plugins.js"></script>

        <script src="scripts/6181b202.modules.js"></script>
</body>
</html>
yo --version && echo $PATH $NODE_PATH && node -e 'console.log(process.platform, process.versions)' && cat Gruntfile.js

1.0.0-rc.1
/usr/local/heroku/bin:/home/gal/.rvm/gems/ruby-1.9.3-p0/bin:/home/gal/.rvm/gems/ruby-1.9.3-p0@global/bin:/home/gal/.rvm/rubies/ruby-1.9.3-p0/bin:/home/gal/.rvm/bin:/usr/local/heroku/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/gal/.rvm/bin /usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
linux { http_parser: '1.0',
  node: '0.10.12',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
  uv: '0.10.11',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1e' }

// Generated on 2013-07-03 using generator-angular 0.3.0
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var mountFolder = function (connect, dir) {
  return connect.static(require('path').resolve(dir));
};

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  // configurable paths
  var yeomanConfig = {
    app: 'app',
    dist: 'dist'
  };

  try {
    yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
  } catch (e) {}

  grunt.initConfig({
    yeoman: yeomanConfig,
    watch: {
      coffee: {
        files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
        tasks: ['coffee:dist']
      },
      coffeeTest: {
        files: ['test/spec/{,*/}*.coffee'],
        tasks: ['coffee:test']
      },
      livereload: {
        options: {
          livereload: LIVERELOAD_PORT
        },
        files: [
          '<%= yeoman.app %>/{,*/}*.html',
          '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
          '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
          '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost'
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              lrSnippet,
              mountFolder(connect, '.tmp'),
              mountFolder(connect, yeomanConfig.app)
            ];
          }
        }
      },
      test: {
        options: {
          middleware: function (connect) {
            return [
              mountFolder(connect, '.tmp'),
              mountFolder(connect, 'test')
            ];
          }
        }
      },
      dist: {
        options: {
          middleware: function (connect) {
            return [
              mountFolder(connect, yeomanConfig.dist)
            ];
          }
        }
      }
    },
    open: {
      server: {
        url: 'http://localhost:<%= connect.options.port %>'
      }
    },
    clean: {
      dist: {
        files: [{
          dot: true,
          src: [
            '.tmp',
            '<%= yeoman.dist %>/*',
            '!<%= yeoman.dist %>/.git*'
          ]
        }]
      },
      server: '.tmp'
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js'
      ]
    },
    coffee: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/scripts',
          src: '{,*/}*.coffee',
          dest: '.tmp/scripts',
          ext: '.js'
        }]
      },
      test: {
        files: [{
          expand: true,
          cwd: 'test/spec',
          src: '{,*/}*.coffee',
          dest: '.tmp/spec',
          ext: '.js'
        }]
      }
    },
    // not used since Uglify task does concat,
    // but still available if needed
    /*concat: {
      dist: {}
    },*/
    rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/scripts/{,*/}*.js',
            '<%= yeoman.dist %>/styles/{,*/}*.css',
            '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= yeoman.dist %>/styles/fonts/*'
          ]
        }
      }
    },
    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>'
      }
    },
    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
      options: {
        dirs: ['<%= yeoman.dist %>']
      }
    },
    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },
    cssmin: {
      // By default, your `index.html` <!-- Usemin Block --> will take care of
      // minification. This option is pre-configured if you do not wish to use
      // Usemin blocks.
      // dist: {
      //   files: {
      //     '<%= yeoman.dist %>/styles/main.css': [
      //       '.tmp/styles/{,*/}*.css',
      //       '<%= yeoman.app %>/styles/{,*/}*.css'
      //     ]
      //   }
      // }
    },
    htmlmin: {
      dist: {
        options: {
          /*removeCommentsFromCDATA: true,
          // https://github.com/yeoman/grunt-usemin/issues/44
          //collapseWhitespace: true,
          collapseBooleanAttributes: true,
          removeAttributeQuotes: true,
          removeRedundantAttributes: true,
          useShortDoctype: true,
          removeEmptyAttributes: true,
          removeOptionalTags: true*/
        },
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: ['*.html', 'views/*.html'],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },
    // Put files not handled in other tasks here
    copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '.htaccess',
            'bower_components/**/*',
            'images/{,*/}*.{gif,webp,svg}',
            'styles/fonts/*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: [
            'generated/*'
          ]
        }]
      }
    },
    concurrent: {
      server: [
        'coffee:dist'
      ],
      test: [
        'coffee'
      ],
      dist: [
        'coffee',
        'imagemin',
        'htmlmin'
      ]
    },
    karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true
      }
    },
    cdnify: {
      dist: {
        html: ['<%= yeoman.dist %>/*.html']
      }
    },
    ngmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.dist %>/scripts',
          src: '*.js',
          dest: '<%= yeoman.dist %>/scripts'
        }]
      }
    },
    uglify: {
      dist: {
        files: {
          '<%= yeoman.dist %>/scripts/scripts.js': [
            '<%= yeoman.dist %>/scripts/scripts.js'
          ]
        }
      }
    }
  });

  grunt.registerTask('server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'concurrent:server',
      'connect:livereload',
      'open',
      'watch'
    ]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'concurrent:test',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'useminPrepare',
    'concurrent:dist',
    'concat',
    'copy',
    'cdnify',
    'ngmin',
    'cssmin',
    'uglify',
    'rev',
    'usemin'
  ]);

  grunt.registerTask('default', [
    'jshint',
    'test',
    'build'
  ]);
};
@passy
Copy link
Member

passy commented Jul 3, 2013

Could you give more information, please? Have a look at the issue guidelines.

@bsphere
Copy link
Author

bsphere commented Jul 3, 2013

sorry, updated the issue..

@passy
Copy link
Member

passy commented Jul 3, 2013

Thanks for the update, I can confirm this. It doesn't happen with the master version of grunt-google-cdn, though.

@btford Could you publish a new release of grunt-google-cdn anytime soon?

@bsphere
Copy link
Author

bsphere commented Jul 21, 2013

any updates on this issue ?

@addyosmani
Copy link
Member

grunt-google-cdn doesn't appear to have had a new npm push in 2 months. I think this issue is still considered open :) @btford would it be possible to give @passy push rights on that module?

@btford
Copy link
Contributor

btford commented Jul 21, 2013

pushed v0.2.2 and added @passy.

sorry for the hold up.

@btford btford closed this as completed Jul 21, 2013
@passy
Copy link
Member

passy commented Jul 21, 2013

Thanks!

@diestrin
Copy link

Is this working right now?

I just updated to v0.2.2 but the same result after run grunt cdnify

<!-- Other content -->
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<!-- Other content -->

cdnify: {
  dist: {
    html: ['<%= yeoman.dist %>/*.html']
  }
}

Log:

$ grunt cdnify
Running "cdnify:dist" (cdnify) task
Going through deploy/index.html to update script refs

Thanks in advance.

@patrickrs
Copy link

@passy this still doesn't appear to work with [email protected]

@X1011
Copy link

X1011 commented Oct 5, 2013

@diestrin, @patrickrs, It doesn't work for me either. I did some investigation, and it seems google-cdn has hard-coded lists of supported versions of packages. Since I am using AngularJS 1.2, which is not on the list, I assume this is why it does not work for me. Rather than try to keep google-cdn updated with every package release, I decided to just use grunt-htmlrefs to manually specify script tag replacements. Here's how I did it.

@seriema
Copy link

seriema commented Nov 18, 2013

Any news on this? It doesn't replace anything for me either.

@lukasz-madon
Copy link

it replaces jQuery only. Angular and other bower components are the same

@korneel
Copy link

korneel commented Jan 10, 2014

@X1011 Thank you!

@JustinAzoff
Copy link

I've been struggling with this issue..

I've come to the following conclusions:

  • google-cdn 0.4.0 seems to work fine when I use the example in the readme.

  • google-cdn 0.1.0 that grunt-google-cdn pulls in does not work. This seems to be due to this line in util/hoist.js:

    var lineRegex = lineRegex(moveLine);

which on nodejs v0.10.21 at least raises a TypeError: undefined is not a function

There also may be an ordering issue in the default build task, cdnify needs to run before all the bower scripts get concatenated.

I'm not really sure what the fix should be here. It seems grunt-google-cdn is what needs to be updated, but maybe yeoman could work around it somehow.

Edit: installing grunt-google-cdn from git://github.com/syamanaka/grunt-google-cdn#develop which has the bumped dependencies made things work mostly better.

Only problem is that the intermediate file looks like:

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>

...

instead of moving the script tags outside the build:js like the older version tried to do.

@scottlepp
Copy link

@JustinAzoff I'm having the same issue. The cdnified scripts are just getting minified since they aren't moved outside the usemin block. Did you come up with a workaround?

@JustinAzoff
Copy link

@leptronic yeah, I got things mostly working. First I had to install the git version of grunt-google-cdn.

so my package.json has:

"grunt-google-cdn": "git://github.com/syamanaka/grunt-google-cdn#develop",
"google-cdn": "^0.4.0",

Then I had to move the cdn capable scripts outside of the bower:js block. This kind of breaks bower, but it's the only thing that worked:

So I have:

<!-- cdn scripts -->
<script src="bower_components/angular/angular.js"></script>
etc

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
etc
<!-- endbower -->
<!-- endbuild -->

@scottlepp
Copy link

Thanks @JustinAzoff . I can't move my cdn scripts though. I need builds that can be cdnified or minified. Maybe I can just create a grunt task that removes the build block comment when I need a cdnified build. It would be nice if usemin could be configured to ignore a build block.

@JustinAzoff
Copy link

Ah. The proper fix is probably to make cdnify play nice with bower and usemin again. It used to (or at least used to try to) do what I did automatically during the build

@matthew-b-payne
Copy link

agreed with JustinAzoff. This should not be closed. cdnify should work with usemin. cdnify the vendor scripts found and usemin the rest.

@davidemoro
Copy link

Hi,

I was able to cdnify jquery on this repo generated with generator-webapp: https://github.com/davidemoro/p_started/tree/master/p_started/webapp

The .html file contains templating language syntax statements because the webapp folder is integrated with a python-based framework, but it should work with plain html as well. Just remove things like tal:comment, tal:attributes, tal:define, etc.

Hope it might help.

@WayneEllery
Copy link

Why was this issue closed? It appears that it's still an issue. I had to move my cdn scripts out as JustinAzoff did.

@computersarecool
Copy link

+1

@syonip
Copy link

syonip commented Mar 7, 2015

I'm having this issue too

@tw-zz-rk
Copy link

+1

edit: the issue appears to be due to the fact that this source file hasn't been updated in 2 yrs
https://github.com/passy/google-cdn/blob/72e44f0121153942a9b77b987c1c3570474ad2d5/lib/data.js

@carchrae
Copy link

someone made a grunt task to hack around this: https://github.com/mjetek/grunt-cdn-nobuild

i suspect this is closed because it is a 'not me' issue. it is very annoying though.

@carchrae
Copy link

see also btford/grunt-google-cdn#47

@carchrae
Copy link

and the open issue (with workaround #955 (comment))

@itsSaad
Copy link

itsSaad commented Nov 2, 2015

So there is no solution and this is closed as well. 👎

@oyeharry
Copy link

oyeharry commented Nov 9, 2015

It was getting same issue on ubuntu 14 server. It was getting stuck for me.

I just stopped the server and tried again and it works ✨ ✨ ✨

@itsSaad
Copy link

itsSaad commented Nov 9, 2015

@oyeharry ah that makes sense. So when im running grunt serve than it gets stuck at cdnify and doesn't move on. We have to stop there server for the file to get written or updated. Thanks man.

@anupraaj
Copy link

Any development on this so far?

@phil-hudson
Copy link

2016, still issues.. :(

@pam81
Copy link

pam81 commented Feb 14, 2017

2017 still issues with cdnify yo angular

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests