Code Monkey home page Code Monkey logo

grunt-jsmin-sourcemap's Introduction

grunt-jsmin-sourcemap Build status

Grunt task for JSMin and source maps.

Synopsis

Grunt is a node.js based CLI build tool.

JSMin is a JavaScript minifier that removes whitespace and comments.

Source maps enables developers to view and interact with minified JavaScript as if it were unminified (providing useful line errors and easier debugging).

When you combine all three of these, you get a grunt plugin that is your new best debugging friend.

Demos

The demos in the node-jsmin-sourcemap, what makes this tick, are hosted on Plunker for your testing and enjoyment.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-jsmin-sourcemap

Then add this line to your project's grunt.js gruntfile:

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

Documentation

grunt-jsmin-sourcemap is registered under the jsmin-sourcemap task. Your initConfig should look similar to this:

grunt.initConfig({
  'jsmin-sourcemap': {
    all: {
      // Source files to concatenate and minify (also accepts a string and minimatch items)
      src: ['public/js/jquery.js', 'public/js/underscore.js'],

      // Destination for concatenated/minified JavaScript
      dest: 'dist/js/all.min.js',

      // Destination for sourcemap of minified JavaScript
      destMap: 'dist/js/all.js.map'

      // Optional root for all relative URLs
      srcRoot: 'some/lower/directory'

      // Optional cwd to resolve from for all URLs
      // Converts jquery.js -> some/higher/directory/jquery.js during lookup but mapping preserves jquery.js in map file
      cwd: 'some/higher/directory'
    },

    // Compact format is also accepted
    'dest/file.js': ['src/file1.js', 'src/file2.js']
  }
});

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 via grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

License

As of Dec 05 2013, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.

Previous to this, it was licensed under the MIT license.

grunt-jsmin-sourcemap's People

Contributors

twolfson 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

Watchers

 avatar  avatar  avatar  avatar  avatar

grunt-jsmin-sourcemap's Issues

Getting Error: AssertionError: "\t" === " "

When I try to use your module I get the above error. I followed your instructions per the repo readme. It says the error occurred here:

at action (/node_modules/grunt-jsmin-sourcemap/node_modules/jsmin-sourcemap/node_modules/jsmin2/lib/jsmin.c.index.js:196:8)

readme says destMap but its map that works

I ran into an odd issue i think its just wrong docs, installed 1.5 from npm and used the docs example but my .map file had a bad file name. it was not using the grunt templating so the result was literally "dist/js/<%= pkg.name %>-<%= pkg.version %>.js.map" i thought this was an oversight in the code but in fact, i could not find "destMap anywhere in the project. However map does exist and once i changed destMap to map everything worked fine. Plz update docs or code whichever is intended.

adding source and dist files in different directories

Sources are in /app
Public files in /dist

my grunt code looks like this:

basic: {
src: ['app//*.js', '!app/main//*.js'],
dest: 'dist/<%= pkg.name %>.js',
destMap: 'dist/<%= pkg.name %>.js.map',
sourceRoot: '../app'
}

Generated map file looks like this.
.. "sources":["app/app.js","app/key.js","app/route.js"] ...

I do not see any difference in the map file with or without sourceRoot option and Chrome toolbar is looking for files in dist directory.

Support for adding source and dist files in different directories

Source Files located at : /src
Generated Min file Should be located at /dist

Hence the task looks something like

'jsmin-sourcemap': {
    all: {
      src: ['src/1.js', 'src/2.js'],
      dest: 'dist/all.min.js',
      destMap: 'dist/all.js.map'
    }
  }

The problem in this case is that the the sourceMap line in the minified file points to dist/all.js.map when it should actually point to all.js.map. Chrome seems to look at the path relative to the minified javascript file.

Also, inside the sourcemap, the paths of individual source files is src/1.js and chrome looks for this relative to the minified file, hence looking at dist/src/1.js

Source URL option

I would like to see a option to add the url to the source in the sourcemap file. Since the files arent available in the browser by the filepath with my Django setup, i need to reach them by it's url.

{"version":3,"file":"explorer.js", "sources":["project/myproject/static/js/explorer.js", "....etc"] }

project/myproject/static/ should become /static

{"version":3,"file":"explorer.js", "sources":["/static/js/explorer.js", "....etc"] }

Here's my config

'jsmin-sourcemap': { explorer: { src: ['project/myproject/static/js/explorer.js', 'project/myproject/static/js/explorer.*.js'], dest: 'project/myproject/static/js/dist/explorer.js' }, }

Please update the grunt-retro dependency

I'm seeing an error when using your plugin in Grunt 0.4.1.

It seems that the version of grunt-retro that you are using is very old, and updating to version 0.6.4 resolves my issue.

The error is:

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Cannot call method 'split' of undefined
>>     at Object.grunt.registerTask (/Users/aaronlademann/workspaces/wf/web-skin/node_modules/grunt-jsmin-sourcemap/node_modules/grunt-retro/tasks/retro.js:21:28)
>>     at Object.module.exports (/Users/aaronlademann/workspaces/wf/web-skin/Gruntfile.js:870:19)
>>     at loadTask (/Users/aaronlademann/workspaces/wf/web-skin/node_modules/grunt/lib/grunt/task.js:312:10)
>>     at Task.task.init (/Users/aaronlademann/workspaces/wf/web-skin/node_modules/grunt/lib/grunt/task.js:424:5)
>>     at Object.grunt.tasks (/Users/aaronlademann/workspaces/wf/web-skin/node_modules/grunt/lib/grunt.js:113:8)
>>     at Object.module.exports [as cli] (/Users/aaronlademann/workspaces/wf/web-skin/node_modules/grunt/lib/grunt/cli.js:38:9)
>>     at Object.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:41:20)
>>     at Module._compile (module.js:456:26)
>>     at Object.Module._extensions..js (module.js:474:10)
>>     at Module.load (module.js:356:32)

could add 'uglify' function to this grunt task

This is a very cool task for grunt. I'd like to use this task to build my source map in map. But it seems no way to uglify my minified js. Does it have any chance to add this function? Thanks!

Sourcemaps not generated for more than 2 files

Created a sample project with 3 source files, but source map does not seem to recognize logs for more than 2 files.

Reproduction steps

  1. Download the sample project from http://dl.dropbox.com/u/98924751/tmp/sample.zip
  2. Unzip and navigate into the directory
  3. Run npm install grunt-jsmin-sourcemap to install the grunt-jsmin-sourcemap
  4. Run grunt
  5. Open index.html in a browser (file:// URIs also work for sourcemaps)
  6. Notice that all console.log statement for 2.js are correct, however, console.log for 3.js is incorrect.

Is there anything wrong in the grunt.js file, or is this an error on jsmin-sourcemap ?

Optional source maps

This plugin would be more versatile if it were made such that source maps are an option and not a requirement. Why force users to make source maps?

The only other alternative JS minifier (that I know of) is uglify, which really mangles your code and is unusable in all situations. It'd be great to have a flexible alternative like JSMin!

To commemorate the change, the repository could possible be renamed to be grunt-jsmin.

'use strict' breaks source map line numbers

In trying to figure out why my sourcemap line numbers were sometimes off (and in the wrong file!) I've boiled it down to the following code.

I have two files, file1.js and file2.js.
src/app/testing/file1.js:
'use strict';
var variable1 = 'value1';
console.log(variable1);

src/app/testing/file2.js
'use strict';
var variable2 = 'value2';
console.log(variable2);

The config for these in the gruntfile is:
'jsmin-sourcemap': {
combined: {
src: ['app/testing/*/.js'],
dest: '../target/tmp/combined.min.js',
destMap: '../target/tmp/combined.js.map',
cwd: 'src'
},
}

Finally the index.html file includes

<script src="combined.min.js"></script>

Please forgive the slightly confusing directory structure, but it's how our project is currently setup. "testing" is a folder I made just for these files for now for demonstration purposes.

Anyways when run as is, "value1" and "value2" get printed to the browser's console log in chrome, but both show from the source "file1.js:3".
If I comment out the first line (//'use strict';) in both files, then the source mapping works, and I get "value1 file1.js:3" "value2 file2.js:3" as the browser's console log output. I'm using Chrome with the source maps option turned on.

Let me know if you need any more info to help reproduce.

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

excluse files from jsmin

I'm trying to exclude a file from concat and minify
in grunt-contrib-concat syntax is
src: ['app//*.js', '!app/main//*.js']

Tried similar with sourcemap:
basic: {
src: ['app//*.js', '!app/main//*.js'],
dest: 'dist/<%= pkg.name %>.js',
destMap: 'dist/<%= pkg.name %>.js.map'
}
But unfortunately it does not exclude the files from main directory.
Can someone help how to handle this case?

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.