uglify-save-license

WebJar for uglify-save-license

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

uglify-save-license
Last Version

Last Version

0.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

uglify-save-license
WebJar for uglify-save-license
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/shinnn/uglify-save-license

Download uglify-save-license

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/uglify-save-license/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>uglify-save-license</artifactId>
    <version>0.4.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/uglify-save-license/
implementation 'org.webjars.npm:uglify-save-license:0.4.1'
// https://jarcasting.com/artifacts/org.webjars.npm/uglify-save-license/
implementation ("org.webjars.npm:uglify-save-license:0.4.1")
'org.webjars.npm:uglify-save-license:jar:0.4.1'
<dependency org="org.webjars.npm" name="uglify-save-license" rev="0.4.1">
  <artifact name="uglify-save-license" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='uglify-save-license', version='0.4.1')
)
libraryDependencies += "org.webjars.npm" % "uglify-save-license" % "0.4.1"
[org.webjars.npm/uglify-save-license "0.4.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

uglify-save-license

NPM version Build Status devDependency Status

A support module for UglifyJS to detect and preserve license comments

//     Backbone.js 1.1.2

//     (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
//     Backbone may be freely distributed under the MIT license.
//     For all details and documentation:
//     http://backbonejs.org

(function(root, factory) {

  // Set up Backbone appropriately for the environment. Start with AMD.
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
//...

//     Backbone.js 1.1.2
//     (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
//     Backbone may be freely distributed under the MIT license.
//     For all details and documentation:
//     http://backbonejs.org
!function(a,b){if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(c,d,e){a.Backbone=b(a,e,c,d)});else if("undefined"!=typeof exports){...

Overview

This module enables us to preserve license comments when using UglifyJS.

Even if the license statement is in multiple line comments, or the comment has no directive such as @license and /*!, this module keeps them readable.

Installation

Install with npm. (Make sure you have installed Node.)

npm install --save-dev uglify-save-license

Usage

First of all, load 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 it works

uglify-save-license checks each comment token of a JavaScript file. The comment will be regarded as a license statement and preserved after compression, if it meets at least one of the following requirements:

  1. The comment is in the first line of a file.
  2. The regexp for license statement matches the string of the comment. It matches, for example, MIT and Copyright.
  3. There is a comment at the previous line, and it matches 1. 2. or 3.

Used by

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 file

// First line

// (c) 2014 John  <- contains '(c)'
// The previous line is preserved

// This line won't be preserved.
(function(win, doc) {
  var str = 'Hello World! :' + doc.title;

  // This line will not, too.
  console.log(str);
}(window, document));

Command

node uglify-example.js <target filename>

Output

// First line
// (c) 2014 John  <- contains '(c)'
// The previous line is preserved
!function(o,l){var n="Hello World! :"+l.title;console.log(n)}(window,document);

Gruntfile.coffee example

module.exports = (grunt) ->

  grunt.loadNpmTasks 'grunt-contrib-uglify'
  grunt.loadNpmTasks 'grunt-contrib-concat'
  grunt.loadNpmTasks 'grunt-contrib-clean'
  
  grunt.initConfig
    uglify:
      target:
        options:
          preserveComments: require 'uglify-save-license'
        files: [
          expand: true
          flatten: true
          cwd: 'path/to/src'
          src: ['**/*.js']
          dest: 'tmp/'
        ]

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

    clean:
      tmpdir: ['tmp']

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

Acknowledgements

uglify-save-license is inspired by grunt-license-saver and I used it as reference. Thanks, kyo-ago.

License

Copyright (c) 2013 - 2014 Shinnosuke Watanabe

Licensed under the MIT license.

Versions

Version
0.4.1