thanpolas / grunt-closure-tools

Google Closure Tools for grunt
MIT License
95 stars 22 forks source link

"create_source_map: null" trick only works if >1 mapping is specified. #52

Closed decitrig closed 7 years ago

decitrig commented 10 years ago

If I only have 1 src->dest mapping specified, setting create_source_map: null in compilerOpts does not generate source mappings, since isMapping (in closureCompiler.js) is set to this.files.length > 1. For example,

closureCompiler: {
  options: {
    compilerFile: '/home/rwsims/tools/compiler.jar',
    compilerOpts: {
      create_source_map: null,
    }
  },
  compile: {
    files: {
      'foo.js': [ 'bar.js', 'baz.js' ]
    }
  }
}

will not generate source mappings; it passes an empty create_source_map flag to the compiler.

thanpolas commented 10 years ago

@fhurta can you have a look?

fhurta commented 10 years ago

@thanpolas I confirm the behavior (bug). I'd remove the check for 'isMapping' at all. The null value for create_source_map option would generate value-less parameter, which is invalid for compiler. So it could still have the special meaning of adding the '.map' suffix to the destination file name as I think it is standard naming pattern even in case of compiling all files to a single output, so this scenario could leverage from it too. ?

ixtli commented 10 years ago

I'm also experiencing this :/ I only have a single js file at present and I get the following output:

Running "closureCompiler:minify" (closureCompiler) task
Executing: java  -jar ./compiler.jar  --js js/foo.js --js_output_file=js/foo.min.js --compilation_level ADVANCED_OPTIMIZATIONS --externs  --define 'go
og.DEBUG=false' --warning_level verbose --output_wrapper "(function(){%output%})();" --create_source_map
>> Error: Command failed: Option "--create_source_map" takes an operand

My config looks like this:

module.exports = function (grunt)
{
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        compass: {
            dist: {
                options: {
                    config: 'config.rb',
                    force: true
                }
            }
        },

        closureCompiler: {

            options: {

                compilerFile: './compiler.jar',

                checkModified: true,

                compilerOpts: {
                    compilation_level: 'ADVANCED_OPTIMIZATIONS',
                    externs: [],
                    define: ["'goog.DEBUG=false'"],
                    warning_level: 'verbose',
                    output_wrapper: '"(function(){%output%})();"',
                    create_source_map: null,
                }
            },

            minify: {
                files: [
                    {
                        expand: true,
                        src: ['js/*.js', '!js/*.min.js'],
                        ext: '.min.js'
                    }
                ]
            }

        },

        watch: {
            html: {
                files: ['*.html'],
            },
            js: {
                files: ['js/*.js', '!js/*.min.js'],
                tasks: ['closureCompiler']
            },
            compass: {
                files: ['sass/*.scss'],
                tasks: ['compass'],
            },
            css: {
                files: ['css/*.css'],
                tasks: []
            }
        }
    });
thanpolas commented 7 years ago

closing due to inactivity, feel free to re-open if the issue persists.