Git Product home page Git Product logo

grunt-concat-sourcemap's Introduction

Deprecated: grunt-contrib-concat plugin has features about Source Maps. This plugin is no more maintained. Please use grunt-contrib-concat plugin.

grunt-concat-sourcemap Build Status

Concatenate files and generate a source map file.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-concat-sourcemap --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-concat-sourcemap');

The "concat_sourcemap" task

Overview

In your project's Gruntfile, add a section named concat_sourcemap to the data object passed into grunt.initConfig().

grunt.initConfig({
  concat_sourcemap: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    }
  }
})

Options

options.separator

Type: String Default value: grunt.util.linefeed

The value that will be used to separate lines when generating sourceMappings.

options.sourceRoot

Type: String Default value: ''

An optional root for all relative URLs in the source map.

options.sourcesContent

Type: Boolean Default value: false

An optional flag that tells the source map generator whether or not to include all original sources in the map. sourcesContent is an array of contents of the original source files. This is useful if you don't want to have to upload original src files to the webserver that will be serving the sourcemap.

options.process

Type: Function Default value: undefined

  • undefined - Do not apply any processing to the source files
  • function(src, filepath) - Process source files using the given function, called once for each file. The returned value will be used as source code.

Usage Examples

Default Options

In this example, it will concatenate the two specified source files(in order), joining files with default separator(grunt.util.linefeed) and writing the output to dest/default_options.js and dest/default_options.js.map.

grunt.initConfig({
  concat_sourcemap: {
    options: {},
    target: {
      files: {
        'dest/default_options.js': ['src/a.js', 'src/b.js']
      }
    }
  }
})

Using sourcesContent: true

When using sourcesContent: true the resulting sourceMap will include all the contents of each source file inside of an array called sourcesContent

Given sample files as follows:

src/a.js

"file a - line 1";
"file a - line 2";

src/b.js with contents as follows:

"file b - line 1";

and the following Grunt configuration target for concat_sourcemap

grunt.initConfig({
  concat_sourcemap: {
    options: {
      sourcesContent: true
    },
    target: {
      files: {
        'dest/default_options.js': ['src/a.js', 'src/b.js']
      }
    }
  }
})

You would see a resulting dest/default_options.js.map that included sourcesContent like so:

  {
    "version": 3,
    "file": "default_options.js.map",
    "sources": [
      "src/a.js",
      "src/b.js"
    ],
    "names": [],
    "mappings": "AAAA;AACA;AACA;A;ACFA;AACA;A;ACDA;A",
    "sourcesContent": [
      "\"file a - line 1\";\n\"file a - line 2\";\n",
      "\"file b - line 1\";\n"
    ]
  }

Using process

grunt.initConfig({
  concat_sourcemap: {
    options: {
      process: function(src, filepath) {
        return '(function(){' + src + '})();';
      }
    },
    target: {
      files: {
        'dest/closureWrapped.js': ['src/a.js', 'src/b.js']
      }
    }
  }
})

Merging source map files

If input file has source map linkage(e.g. //# sourceMappingURL=.*), grunt-concat-sourcemap will read the source map and merge it into the new one. No option is needed.

The setting is to consume 2 input files generated by grunt-contrib-coffee with sourceMap: true option.

grunt.initConfig({
  coffee: {
    options: { sourceMap: true },
    target: {
      files: {
        'src/file1.js': ['src/file1.coffee'],
        'src/file2.js': ['src/file2.coffee'],
      }
    }
  },
  concat_sourcemap: {
    target: {
      files: {
        'dest/concatenated.js': ['src/*.js']
      }
    }
  }
})

The source map generated by grunt-concat-sourcemap is as below. It refers to original coffee script source files.

{
  "version": 3,
  "file": "concatenated.js",
  "sources": [
    "src/file1.coffee",
    "src/file2.coffee"
  ],
  "names": [],
  "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;A"
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

grunt-concat-sourcemap's People

Contributors

davemo avatar dobogo avatar joliss avatar kozy4324 avatar maks3w avatar michaek avatar mrcljx avatar shinnn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

grunt-concat-sourcemap's Issues

Use with input sourcemap has null sourcesContent

In this example, I have two grunt tasks. The first, compiles Sass files to CSS, generating sourcemaps. The second concatenates the generated CSS files with grunt-concat-sourcemap. My output sourcemap is the following:

{
  "version": 3,
  "file": "app.css",
  "sources": [
    "app/stylesheets/one.scss",
    ".tmp/stylesheets/one.css",
    "app/stylesheets/two.scss",
    ".tmp/stylesheets/two.css"
  ],
  "names": [],
  "mappings": "AAAA;ACCA,K;ACDA;ACCA,K",
  "sourcesContent": [
    null,
    ".one{font-weight:bold;}.uno{font-style:italic;}\n/*# sourceMappingURL=one.css.map */",
    null,
    ".two{font-weight:bold;}.dos{font-style:italic;}\n/*# sourceMappingURL=two.css.map */"
  ]
}

Most obviously, the sourcesContent for the *.scss source files is null. But it seems that there's no reason (in this case) for the *.css source files and their sourcesContent to be included in the sourcemap.

I understand that this doesn't represent all cases - in some cases there may be a necessity to merge the input sourcemap with "original" source mappings from a single file, though it's hard for me to imagine this in practice. That said, I'm curious if there may be a way to exclude the *.css sources if there's nothing to merge.

Source maps not read correctly when source file path contains spaces

When my source code is in a path with spaces, e.g. "Source Code", this task fails with the following output:

Running "concat_sourcemap:scripts" (concat_sourcemap) task
[D] Task source: /.../node_modules/grunt-concat-sourcemap/tasks/concat_sourcemap.js
Warning: Unable to read "Source%20Code/app.litcoffee" file (Error code: ENOENT). Use --force to continue.

concat_sourcemap options:

{
    sourcesContent: true
}

Including "./" in sourceRoot causes weird path concatenation in Windows

Target config:

concat_sourcemap: {
    main: {
        files: {
            './build/build.js': filesToBuild
        },
        options: {
            sourceRoot: './build/tmp/lib',
            sourcesContent: true
        }
    }
},

Error message:

Warning: "build/tmp/lib/ d:/path-to-project/build/tmp/lib/somefile.js" is not in the SourceMap. Use --force to continue.

Add sourceMap: false option

This may be beyond the scope of what you're doing but I thought I'd propose it anyway: add an option for sourceMap: false that allows you to concatenate without generating a sourcemap.

I recognize this can be done simply by using grunt-contrib-concat but it seems a little silly to have two plugins, especially since I'm concatenating / minifiying locally expressly for the purpose of mirroring production as closely as possible and thus it would be great to be using the same plugin too.

Happy to help implement; I just wanted to make sure that was interesting to you.

Publish stable tag

Since the last release many changes has been added. I think is good to make a new release tag.

Process embedded source maps

I'm trying to use a grunt-concat-sourcemap task after a grunt-browserify task but I'm getting a warning as grunt-concat-sourcemap is trying to use the encoded string as a filename to open.

Browserify embeds the source map as a base64 encoded string, i.e: data:application/json;base64.

Could this plugin detect the embedded source map, decode it and use it directly?

wrong CSS sourceMappURL line

I may just be missing a configuration line, but from the code it looks like on line 79 the output is always:

sourceNode.add('//@ sourceMappingURL=' + mapfilepath);

This does not work for CSS files. It instead should output:
/*# sourceMappingURL=master.css.map */

Which works in Chrome.

Incorrect configuration examples in Readme.md

The configuration examples shows:

    files: {
      'dest/default_options.js': ['src/a.js', 'src/b.js']
    }

as the syntax for specifying the source and destination files when it should be:

    'dest/default_options.js': ['src/a.js', 'src/b.js']

At least that's what I had to use in order to get things working.

Input source map?

Uglify has an option for --in-source-map to generate a source map based on JavaScript that's already compiled from somewhere else. Is there a reason to support that feature in grunt-concat-sourcemap? (Or does it already exist, and I've overlooked it?)

Change sourceMappingURL

Since my sourcemap must be relative to the web root, I want to manually set my sourceMappingURL (ie /# sourceMappingURL=scripts.js.map). sourceRoot doesn't seem to do this.

Travis CI setting

Test! Test! Test!

It is necessary to configure automation test with multiple Node environments.

Is it feasible to add support for `sourcesContent`?

I was reading the mozilla documentation and came across sourcesContent: Optional. An array of contents of the original source files.

Would it be feasible to add an option to grunt-concat-sourcemap so that sourcemaps could be entirely self contained, including the mappings and the original sources? The reason I think this would be useful is that it would simplify server-side configuration and avoid having to upload original src files along with the map; unless I'm misunderstanding the purpose of soucesContent

Thoughts?

Sources path not set correctly for Windows (0.4.3)

The paths for source map files aren't proceeded correctly on windows.
They include backslashes instead of slashes, and the maps aren't working.

I use this:

concat_sourcemap: {
    target: {
        files: {
            'path/output.js': ['another-path/**/*.js']
        }
    }
}

After running grunt i get an output like this:

{
    "version": 3,
    "file": "output.js",
    "sources": [
        "src\\file.coffee"
    ],
    "names": [],
    "mappings": "..."
}

path shortening

Background: I currently run my grunt build at the full app (server+client) root, so that i can have Maven (via frontend-maven-plugin) run the grunt build on the CI server and thereby avoid checking grunt build artifacts into git.

The result, given our server setup, is that all css and js live (and are built) under a 'src/main/resources/static' directory/path. This directory is not part of the deployed path, but nonetheless ends up in the sourcemap file paths, thereby making the browser unable to find the source files listed in the map. To say it another way, the css ends up correctly at 'http://server/css/result.css', the map ends up correctly at 'http://server/css/result.css.map', but the sources are listed in the map as 'src/main/resources/static/css/source.css' instead of just 'source.css'.

I need an option to truncate the 'src/main/resources/static/css' off of the file paths. Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.