JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 110950
  • Score
    100M100P100Q166444F
  • License MIT

Tiny license detector module for UglifyJS's 'comments' option

Package Exports

  • uglify-save-license

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uglify-save-license) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

uglify-save-license

NPM version Build Status devDependency Status

Tiny license detector module for the comments option of UglifyJS

Installation

Install Node and run this command in the root of your project:

npm install uglify-save-license

Usage

First of all, load the uglify-save-license module.

var saveLicense = require('uglify-save-license');

Use with UglifyJS

Pass this module to the comments option.

var result = UglifyJS.minify('file1.js', {
  output: {
    comments: saveLicense
  }
});

Use with grunt-contrib-uglify

Pass this module to the preserveComments option.

grunt.initConfig({
  uglify: {
    my_target: {
      options: {
        preserveComments: saveLicense
      },    
      src: ['src/app.js'],
      dest: 'dest/app.min.js' 
    }
  }
});

How does it works

Coming soon.

Examples

CLI tool example

Main script (uglify-example.js)

#!/usr/bin/env node

var UglifyJS    = require('uglify-js'),
    saveLicense = require('uglify-save-license');

var minified = UglifyJS.minify(process.argv[2], {
  output: {
    comments: saveLicense
  }
}).code;

console.log(minified);

Target uncompressed file

// example.js

// (c) John Smith | MIT License
// http://examplelibrary.com/

// anonymous function
(function(win, doc){
  var string = 'Hello World! :' + doc.title;

  // output greeting message
  console.log(string);
}(window, document));

Command

node uglify-example.js [TARGET_FILE_NAME]

Output

// example.js
// (c) John Smith | MIT License
// http://examplelibrary.com/
!function(o,l){var n="Hello World! :"+l.title;console.log(n)}(window,document);

Gruntfile example

module.exports = (grunt) ->

  grunt.loadNpmTasks 'grunt-contrib-uglify'
  grunt.loadNpmTasks 'grunt-contrib-concat'
  grunt.loadNpmTasks 'grunt-contrib-clean'
  
  saveLicense = require 'uglify-save-license'

  grunt.initConfig
    uglify:
      target:
        options:
          preserveComments: saveLicense
        files: [
          expand: true
          flatten: true
          cwd: 'path/to/src'
          src: ["**/*.js"]
          dest: 'tmp/'
        ]

    concat:
      script:
        src: ['tmp/*.js']
        dest: 'path/to/build/app.js'

    clean:
      tmpfiles: ['tmp']

  grunt.registerTask 'default' ['uglify', 'concat', 'clean']

License

Copyright (c) 2013 Shinnosuke Watanabe All rights reserved.

Licensed under the MIT license.