Search code examples
javascriptgruntjsbrowserifysource-mapsgrunt-browserify

How to pass file name/options to Grunt minifyify


I'm using the minifyify plugin as recommended by this answer but I can't seem to find any way to pass flags/options to it when used with Grunt.

Here is the relevant part of my Gruntfile:

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
        options: {
            browserifyOptions: {
                debug: true
            },
            exclude: [/*...all vendor packages...*/],
            transform: [
                'brfs',
                'debowerify',
                'deamdify'
            ]
        },
        app: {
            files: [{
                expand: true,
                cwd: 'web/resources/js',
                src: '**/*.js',
                dest: 'web/assets/js',
                ext: '.min.js',
                extDot: 'last'
            }],
            options: {
                plugin: ['minifyify']
            }
        }
    }
});

The compiled files are appended to with //# sourceMappingURL=bundle.map, which is incorrect. Also, the map files aren't being written to disk or generated at all.

How can I pass options in so that the sourceMappingURL is the same as the file name? So for example:

  • /web/assets/js/foo.min.js -> /web/assets/js/foo.js.map
  • /web/assets/js/bar.min.js -> /web/assets/js/bar.js.map
  • and so on...

Solution

  • you can pass options into grunt-browserify plugins/transforms if you pass in the transform as an array with the name as first item, and the options-object as the second:

    plugin: [['minifyify', {your: 'options'}]]
    

    for the transform option it is documented here: https://github.com/jmreidy/grunt-browserify#transform

    for the plugin-option there is no documentation, but they generally work the same (see lib/runner.js, ans search for options.plugin)