grunt-contrib-concat icon indicating copy to clipboard operation
grunt-contrib-concat copied to clipboard

Add sourceMapURL and sourceMapRootpath options

Open donaldpipowitch opened this issue 11 years ago • 4 comments

Thanks for adding source map support to concat. It would be great if you could add two more options: sourceMapURL and sourceMapRootpath as in grunt-contrib-less.

I use two connect servers for development: one for the app itself and one to serve the source maps. (So my app can't accidentally get the source files. And I can use one source maps server for multiple versions of my app - like production and release version - as the source files are the same.)

This is how the behavior differs:

// ./dist/app.js
// code here...

// source map with relative path
//# sourceMappingURL=app.js.map
// ./dist/style.css:
// styles here...

// source map with absolute path
/*# sourceMappingURL=http://0.0.0.0:8082/dist/style.css.map */
// ./dist/app.js.map
// source map with relative path
{"version":3,"sources":["../src/some-file.js", ...
// ./dist/style.css.map
// source map with absolute path
{"version":3,"sources":[""http://0.0.0.0:8082/src/some-file.less", ...

Settings would look like this:

        options: {
          sourceMap: true,
          sourceMapURL: 'http://0.0.0.0:8082/dist/app.js.map',
          sourceMapRootpath: 'http://0.0.0.0:8082',
          sourceMapStyle: 'link'
        },

Update: A quick fix using string-replace for everyone who wants a similar feature (customize the settings as you need it):

    'string-replace': {
      'js-source-map-fix': {
        files: {
          'dist/': [
            'dist/app.js',
            'dist/app.js.map'
          ]
        },
        options: {
          replacements: [
            {
              pattern: '//# sourceMappingURL=app.js.map',
              replacement: '//# sourceMappingURL=http://0.0.0.0:8082/dist/app.js.map'
            },
            {
              pattern: /"..\//gi,
              replacement: '"http://0.0.0.0:8082/'
            }
          ]
        }
      }
    },

Another question: Are you re-applying existing source maps as you don't have a sourceMapIn option like grunt-contrib-uglify? While releasing I use concat twice: I concatenate all my own files first and at a later state I concatenate all my 3rd-party dependencies and with my own file to the final file which will be deployed.

donaldpipowitch avatar Jul 28 '14 06:07 donaldpipowitch

@jmeas @mzgoddard ping

vladikoff avatar Jul 28 '14 07:07 vladikoff

ping again

candrews avatar Feb 10 '15 22:02 candrews

PRs welcome!

jamesplease avatar Feb 10 '15 22:02 jamesplease

:+1:

Driklyn avatar Feb 27 '15 22:02 Driklyn