dciccale / grunt-processhtml

Process html files at build time to modify them depending on the release environment
MIT License
407 stars 30 forks source link

${TEXT} causes a warning: TEXT is not defined Use --force to continue in v0.3.3+ #69

Closed lz000 closed 9 years ago

lz000 commented 9 years ago

I have "${lang}" in my html and this caused a warning: "lang is not defined Use --force to continue". The issue does not exist in 0.3.2. Any idea?

fdeberle commented 9 years ago

Facing the same problem here.

Looks like it is related to options.templateSettings: https://github.com/dciccale/grunt-processhtml/compare/0.3.2...0.3.3

dciccale commented 9 years ago

Maybe @fdeberle what are your grunt options for the plugin @lz000 ?

fdeberle commented 9 years ago

I guess nothing special about it:

processhtml: {
            prod: {
                options: {
                    process: true
                },
                files: [
                    {
                        expand: true,
                        cwd: 'distProd/',
                        src: ['*.html'],
                        dest: 'distProd/',
                        ext: '.html'
                    }
                ]
            }
        }
dciccale commented 9 years ago

looking into this issue, i was able to replicate it will do some tests to see why that happens.

dciccale commented 9 years ago

if you remove the option process: true it will work. If that option is true, the whole already processed html will go through lodash template to replace variables in the file. it seems that lodash is trying to replace ${lang} with some value, the weird thing is that lodash/underscore template default settings uses <% %> kind of syntax.

you need to escape that expression

dciccale commented 9 years ago

newer version of lodash uses ES6 interpolation check this issue https://github.com/lodash/lodash/issues/1009

so if you want to use process: true you need to change the templateSettings option to something else like the old ones:

    processhtml: {
      prod: {
        options: {
          process: true,
          templateSettings: {
            interpolate: /<%=([\s\S]+?)%>/g
          }
        },
        files: [
          {
            expand: true,
            cwd: '.',
            src: ['*.html'],
            dest: 'distProd/',
            ext: '.html'
          }
        ]
      }
    }