1

I'm developing an angular application and uses ejs to create template and grunt to concat(js, css) minify (js, css and html) and uglify (js) the files.

The index.ejs:

<!DOCTYPE html>
<html>
    <head lang="en">
        <!-- head tags -->
        <% if(isDev) { %>
        <!-- css links for dev-->
        <% } else { %>
        <!-- css links for production-->
        <% } %>
    </head>

    <body >
        <div ng-app="app">
            <ng-view ></ng-view>
            <%- include header.ejs %>
            <!-- more ejs templates... -->
        </div>
        <% if(isDev) { %>
            <!-- JS scripts for dev-->
        <% } else { %>
        <script type="text/javascript" src="/js/app.min.js"></script>
        <% } %>
    </body>
</html>

The grunt file:

module.exports = function (grunt) {
grunt.initConfig({
    rootSource: __dirname + '/public',
    rootTarget: __dirname + '/dist',
    concat:     {
        //Concatenating the css and js
    },
    uglify:     {
        //Uglifies the js files - works fine
    },
    cssmin:     {
        //Minifies CSS files - works fine
    },
    ejs:        {
        app: {
            options: {isDev: false},
            src:['<%= rootSource %>/html/index.ejs'],
            dest:    '<%= rootTarget %>/views/app-ejs.html'
        }            
    },
    htmlmin:{
        dist: {
            options: {
                removeComments:     true,
                collapseWhitespace: true
            },
            files:   {
                '<%= rootTarget %>/views/app.html': '<%= rootTarget %>/views/app-ejs.html'
            }
        }
    },
    clean:[] //Clean files        
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-ejs');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-clean');
// Default task(s).
grunt.registerTask('default', ['concat', 'uglify', 'cssmin', 'ejs', 'htmlmin', 'clean']);
};};

The ejs works fine and creates the app-ejs.html file. The htmlmin creates a file from app-ejs.html with just the code in the index.ejs file that is before the includes and the first 2 lines of the first included file (header.ejs) minified. The rest of the html code is untouched.

How do I solve this?

Thanks!

Gilad S
  • 1,753
  • 1
  • 13
  • 14

0 Answers0