Coder Social home page Coder Social logo

minifyify's Introduction

Minifyify

Tiny, Debuggable Browserify Bundles

Build Status Downloads Dependency Status

WARNING: Unmaintained!

I have stopped writing Javascript full-time, and therefore do not use Minifyify anymore. While I will continue to accept pull requests and keep the test suite running, you should consider better-maintained alternatives, such as uglifyify. Thank you for your support!

Why use Minifyify?

Before, browserify made you choose between sane debugging and sane load times. Now, you can have both.

Minifyify is a browserify plugin that minifies your code. The magic? The sourcemap points back to the original, separate source files.

Now you can deploy a minified bundle in production, and still have meaningful stack traces when things inevitably break!

Advantages

There are advantages to using minifyify over your current minification solution:

  • Reliability

If you are currently using uglifyify and realized that your sourcemap is behaving strangely, you're not alone. Minifyify builds its own sourcemap instead of depending on uglify-js's insourcemap option, and has proven to be more reliable in practice.

  • Smaller Bundles

If you are currently running uglify-js on the bundle browserify outputs, minifyify can give you a smaller bundle because it removes dead code before browserify processes requires in it.

For example:

if(process.env.browser) {
  var realtime = require('socket-io.client')
}
else {
  var realtime = require('socket-io')
}

Only one of the required modules will be in your output bundle, because minifyify runs uglify on each individual file before browserify does its bundling.

  • A Neater Web Inspector

Minifyify allows you to transform those obnoxious absolute paths in your web inspector with compressPath.

  • CoffeeScript Support

Minifyify is tested against CoffeeScript, and can map minified code all the way back to the original .coffee files.

CoffeeScript support is janky because of this issue. The sourcemap that coffee-script produces is wrong, so I had to skip over minifyify's CoffeeScript test. minifyify won't crash, but the test suite validates sourcemaps for correctness. Use at your own risk!

Usage

Programmatic API

var browserify = require('browserify')
    // As of browserify 5, you must enable debug mode in the constructor to use minifyify
  , bundler = new browserify({debug: true});

bundler.add('entry.js');

bundler.plugin('minifyify', {map: 'bundle.js.map'});

bundler.bundle(function (err, src, map) {
  // Your code here
});

The map option should be the location of the sourcemap on your server, and is used to insert the sourceMappingURL comment in src.

Command Line

$ browserify entry.js -d -p [minifyify --map bundle.js.map --output bundle.js.map] > bundle.js

The --output option is a required option on the command line interface and specifies where minifyify should write the sourcemap to on disk.

Passing options to uglify-js is as easy as passing extra parameters in as an uglify object.

$ browserify entry.js -d -p [minifyify --map bundle.js.map --output bundle.js.map --uglify [ --compress [ --dead_code--comparisons 0 ] ] ] > bundle.js

In the example above, if you want to invoke minifyify to only minify without generating any source maps or references to it (which is done by setting [options.map] to false programatically), you can pass --no-map instead of --map and --output, like this:

$ browserify entry.js -d -p [minifyify --no-map] > bundle.js

Options

[options.compressPath]

Shorten the paths you see in the web inspector by defining a compression function.

// A typical compressPath function
compressPath: function (p) {
  return path.relative('my-app-root', p);
}

If a string is provided, it will be used instead of my-app-root in the function above. This is useful if you are working from the command line and cannot define a function.

Defaults to a no-op (absolute paths to all source files).

[options.map]

This is added to the bottom of the minified source file, and should point to where the map will be accessible from on your server. More details here.

Example: If your bundle is at mysite.com/bundle.js and the map is at mysite.com/map.js, set options.map = '/map.js'

Set to false to minify, but not produce a source map or append the source map URL comment.

[options.minify]

Set to false to disable minification and source map transforms. This essentially turns minifyify into a pass-thru stream.

If you set it to an object, it will be passed as the options argument to uglify.minify.

[options.output]

Specify a path to write the sourcemap to. Required when using the CLI, optional when working programmatically.

[options.uglify]

Will be passed to uglify.minify

[options.include]

Pattern(s) matching the files you want included. Defaults to '**/*' (include everything). null/undefined, a single string, and an array of strings are all acceptable values. You have the full range of glob patterns available to you, so you can do app/{moduleA,moduleB}/*.js, etc.

[options.exclude]

Pattern(s) matching the files you want excluded. By default nothing is excluded. Like include; null, a string, and an array of strings are all acceptable. Exclude always wins over include. If a file matches both the include and exclude pattern arrays, it will be excluded.

[options.base]

By default all glob strings are matched against relative paths from process.cwd() (your projects base directory). This option allows you to changed that. base:'subDirA' means evaluate globs relative from that sub directory. base:'/' means test your glob pattern against absolute file paths.

FAQ

  • PARSE ERROR!

    Are you using brfs? Pin it to version 1.0.2. See issue #44 for details.

  • Wait.. Why did the total size (source code + map) get BIGGER??

    It's not immediately obvious, but the more you minify code, the bigger the sourcemap gets. Browserify can get away with merely mapping lines to lines because it is going from uncompressed code to uncompressed code. Minifyify squishes multiple lines together, so the sourcemap has to carry more information.

    This is OK because the sourcemap is in a separate file, which means your app will be snappy for your users as their browsers won't download the sourcemap.

  • How does this work?

    Minifyify runs UglifyJS on each file in your bundle, and transforms browserify's sourcemap to map to the original files.

  • Why does the sourcemap cause my debugger to behave erratically?

    Some of the optimizations UglifyJS performs will result in sourcemaps that appear to broken. For example, when UglifyJS uses the comma operator to shorten statements on different lines, a single debugger "step" in minified code may execute multiple lines of the original source.

    Another common example of erratic behavior is when code like this is compressed:

    var myThing = myFunc('a')
      , cantGetHere = myFunc('b');
    

    If you set a breakpoint on the second line, your debugger might not pause execution there. I've found that setting the breakpoint on the first line and stepping onto the second line is more reliable.

Other Modules

minifyify not working for you? try gulp-sourcemaps.

License

The MIT License (MIT)

Copyright (c) 2013-2014 Ben Ng

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

minifyify's People

Contributors

apaleslimghost avatar axelpale avatar basicallydan avatar bendrucker avatar chemerisuk avatar cperryk avatar flodiebold avatar gkatsev avatar iamjoetaylor avatar jamestalmage avatar jfirebaugh avatar joaojeronimo avatar joeybaker avatar kesla avatar krippy2k avatar mathroc avatar metasansana avatar mohd-akram avatar nfvs avatar piranna avatar tmcw avatar tobiastom avatar wizrd 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  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  avatar  avatar  avatar  avatar  avatar

minifyify's Issues

Broken docs example

there is another problem with this

bundle('entry.js')
  .bundle({debug: true})

causeing

Property 'bundle' of object #<Object> is not a function

Line 25 + Line 58

should be

bundle.add('entry.js');
bundle.bundle({debug: true})

Build fails if specifying minify: false with other config options

The below configuration causes the error Fatal error: Cannot read property 'length' of null. This happens when specifying compressPath map or output. It seems to be specific to the source map options since adding random options works just fine.

{
  minify: false,
  output: someLocation + "/bundle.map.json"
}

Fatal error: Unexpected token: punc (:)

Minifying bpmn-js, a fairly large project, fails with

Fatal error: Unexpected token: punc (:)

Any ideas what might cause the problem? I was trying to trace down the bug but no luck.

The project minifies O.K. when uglify-js is used after the bundle has been built.

This commit adds minifyify.

Platform:
Windows 7, 64bit

Javascript API error

I've been trying to get minifyify to work in my gulpfile, but I keep getting

Cannot read property 'bundle' of undefined

My gulp task is below

var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var debowerify = require('debowerify');
var minifyify = require('minifyify');
var source = require('vinyl-source-stream');

gulp.task('js', ['jscs', 'lint'], function() {
    return browserify({
            entries: './app/scripts/app.js',
            extensions: ['.js', '.jsx']
        })
        .transform(reactify)
        .transform(debowerify)
        .bundle({debug: true})
        .pipe(minifyify())
        .pipe(source('app.js'))
        .pipe(gulp.dest('build/scripts/'));
});

I've also tried removing the browserify opts parameter and instead using .add('./apps/scripts/app.js'), as well as removing everything after the pipe to minifyify on the off chance gulp just isn't playing well with minifyify. Neither of these seemed to work.

It looks like the flow is fairly similar to another issue from a couple months ago, and the provided solution code from there doesn't seem to work, either.

Would love any help with this, as the idea behind this library is just awesome!

Invalid JS output?

I'm seeing weird output from minifyify

$ echo "var x = 1;" > source.js
$ browserify -d source.js | minifyify 

var x=1;
},{}]},{},[1])

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVuZGxlLmpzIiwic291cmNlcyI6WyIvVXNlcnMvYW5kcmV3L3Byb2plY3RzL3Rlc3Qvc291cmNlLmpzIl0sIm5hbWVzIjpbIngiXSwibWFwcGluZ3MiOiI7QUFBQSxHQUFJQSxHQUFJIiwic291cmNlc0NvbnRlbnQiOlsidmFyIHggPSAxO1xuIl19

It's lost the initial part of the JS. The un-minified output is:

$ browserify -d source.js 
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var x = 1;

},{}]},{},[1])
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdGVkLmpzIiwic291cmNlcyI6WyIvdXNyL2xvY2FsL2xpYi9ub2RlX21vZHVsZXMvYnJvd3NlcmlmeS9ub2RlX21vZHVsZXMvYnJvd3Nlci1wYWNrL19wcmVsdWRlLmpzIiwiL1VzZXJzL2FuZHJldy9wcm9qZWN0cy90ZXN0L3NvdXJjZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0EiLCJzb3VyY2VzQ29udGVudCI6WyIoZnVuY3Rpb24gZSh0LG4scil7ZnVuY3Rpb24gcyhvLHUpe2lmKCFuW29dKXtpZighdFtvXSl7dmFyIGE9dHlwZW9mIHJlcXVpcmU9PVwiZnVuY3Rpb25cIiYmcmVxdWlyZTtpZighdSYmYSlyZXR1cm4gYShvLCEwKTtpZihpKXJldHVybiBpKG8sITApO3Rocm93IG5ldyBFcnJvcihcIkNhbm5vdCBmaW5kIG1vZHVsZSAnXCIrbytcIidcIil9dmFyIGY9bltvXT17ZXhwb3J0czp7fX07dFtvXVswXS5jYWxsKGYuZXhwb3J0cyxmdW5jdGlvbihlKXt2YXIgbj10W29dWzFdW2VdO3JldHVybiBzKG4/bjplKX0sZixmLmV4cG9ydHMsZSx0LG4scil9cmV0dXJuIG5bb10uZXhwb3J0c312YXIgaT10eXBlb2YgcmVxdWlyZT09XCJmdW5jdGlvblwiJiZyZXF1aXJlO2Zvcih2YXIgbz0wO288ci5sZW5ndGg7bysrKXMocltvXSk7cmV0dXJuIHN9KSIsInZhciB4ID0gMTtcbiJdfQ==

I'm using browserify version 3.20.0

Shouldn't this code be part of uglify?

I have the feeling that minifyify is not specific to browserify and is a wrapper around uglify to make it accept inline sourcemaps.

Shouldn't this be part of uglify itself then?

Unexpected behavior for map=false

in my case i got a setup like this:

var browserify = require('browserify');
var coffeeify = require('coffeeify');

var paths = {
    scripts: [
        './resources/scripts/test1.js',
        './resources/scripts/test2.js'
    ],
    build: './static/'
} 

gulp.task('scripts', function () {
    if (debug) {
        browserify(paths.scripts, {'extensions': ['.coffee']})
            .external('jquery')
            .transform(coffeeify)
            .plugin('minifyify', {
                map: 'md.min.map',
                compressPath: function (p) {
                    return path.relative('.', p);
                }
            })
            .bundle({debug: true}, function (err, src, map) {
                if (err) console.log(err);
                fs.writeFileSync(paths.build + 'md.min.js', src);
                fs.writeFileSync(paths.build + 'md.min.map', map);
            });
    }
    else {
        browserify(paths.scripts, {'extensions': ['.coffee']})
            .external('jquery')
            .transform(coffeeify)
            .plugin('minifyify', {
                map: false
            })
            .bundle({debug: false}, function (err, src, map) {
                if (err) console.log(err);
                fs.writeFileSync(paths.build + 'md.min.js', src);
            });
    }
});

when i switch my context from debug to production i want the same workflow + output but no sourcemaps.

so i turn this off with map: false.

as a result i got a file which isn't minified and contains an internal sourcemap.

also switching debug: true/false doesn't seem to have an effect.

with disabled minifyify plugin and debug: false i got a browserified file without sourcemap and without minification.


https://github.com/ben-ng/minifyify/blob/master/lib/minifier.js#L35

there is a forced turn off of the minification (but disabling this brings up errors i couldn't solve)

and additionally there is the inline sourcemaps which appears with minifyify plugin.

Transforms defined in submodules' package.jsons may be applied twice

For example, if submodule has package.json with the browserify key:

browserify: {
  transform: ['hbsfy']
}

and the user has already specified hbsfy as a transform they would like to perform, it will be applied twice to any .hbs files inside submodule, resulting in templates that output precompiled javascript.

Issue with not having target directory

Hi.

Trying to use the plugin in my build system and found an issue. If a target directory for a *.map file does not exist, the plugin fails with error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open 'public/js/order.js.map'
\
npm ERR! [email protected] prerestart: `gulp test && NODE_ENV=production gulp manifest`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the [email protected] prerestart script.
npm ERR! This is most likely a problem with the takson package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gulp test && NODE_ENV=production gulp manifest
npm ERR! You can get their info via:
npm ERR!     npm owner ls appname
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 2.6.32-28-server
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "restart"
npm ERR! cwd /var/www/appname
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /var/www/appname/npm-debug.log
npm ERR! not ok code 0

I guess you just need to verify this case and to create a directory on demand.

Absolute path in host being exposed in sourcemap

My sourcemap is starting with

{"version":3,"file":"bundle.js","sources":[<lots of absolute paths to the javascript files in my computer]>

Even some paths inside node_modules are referred to (/home/felipe/site/node_modules/grunt-browserify/node_modules/browserify/node_modules/browser-pack/_prelude.js).
Am I doing something wrong? Why is this necessary? Can I turn it off?
๐Ÿ˜Ÿ

Read Me Clarifications

In the readme, what is bundle.map.json and bundle.json supposed to be?

browserify entry.js -p [minifyify --output bundle.map.json] > bundle.json

Is bundle.json actually bundle.js? Isn't it a JavaScript file instead of json?

and it looks like the map file referenced in at the bottom of bundle.json (bundle.js) is named bundle.map?

//# sourceMappingURL=bundle.map

So maybe the readme should look like this?

browserify entry.js -p [minifyify --output bundle.map] > bundle.js

Support for coffeescript

Hej ben, first of all i like to say thank you for your awesome lib. it really enriched my workflow. but... there is still one thing missing i couldn't get running:

coffeescript with sourcemaps

well.. browserify + coffeescript works fine.
as do browserify + minifyify + sourcemaps
and browserify + coffeescript + minifyify.

but browserify + coffeescript + minifyify + sourcemaps just won't work.

did you ever tried this out?
know a workaround?
like to support this as a future feature?

thanks

Run browserify in debug mode to use minifyify

Using Browserify 5.9.1 & Minifyify 4.0.2:

var browserify = require( 'browserify' );
var minify     = require( 'minifyify' );

module.exports = function(){
    return browserify( {
            debug : true,
            entry : './src/javascript/index.js'
        } )
        .plugin( 'minifyify', {
            map    : 'app.js.map',
            output : './build/scripts/app.js.map'
        } )
        .bundle()
        .pipe( source( 'app.js' ) )
        .pipe( gulp.dest( './build/js/' ) )
        .pipe( sync.reload( {
            stream: true
        } ) );
};

Somehow, Minifyify doesn't believe Browserify is working in debug mode. Might this have something to do with the fact that Browserify now produces maps regardless of debug mode?

sourceMapRoot is not working

Genarated source maps show absolute paths from the filesystem root, showing directories from the developer home folder. They should be created instead using the project directory as root, but it's not doing so and defining sourceMapRoot or any of the other UglifyJS source map flags doesn't work, too.

map: false not being checked

The docs mention being able to minify without creating the source map but passing the map option a value of false. Looks like the check is being done on the minify option instead.

      // Write the sourcemap to the specified output location
      if(minifyifyOpts.minify && minifyifyOpts.output) {

I'm thinking that should be

      // Write the sourcemap to the specified output location
      if(minifyifyOpts.map && minifyifyOpts.output) {

optimize bundling

package.json files don't all need to be copied. just walk upwards from each source file and copy the first one found.

Options not being passed to uglify.minify

I saw #48 and tried to pass the following as my minifyify config:

    b.plugin('minifyify', {
      map: './app.map.json',
      output : './build/js/app.map.json',
      warnings : true,
      compress : {
        drop_debugger : false
    });

But this doesn't seem to be working -- I don't see any uglify warnings, and my debugger statements are dropped in the minified bundle. Did something else change?

npm install fails

It appears this module defined in package.json is throwing a 404: https://codeload.github.com/ben-ng/UglifyJS2/tar.gz/sourcemap-offset-fix

Sample npm install output:

npm http GET https://registry.npmjs.org/minifyify
npm http 200 https://registry.npmjs.org/minifyify
npm http GET https://registry.npmjs.org/minifyify/-/minifyify-0.4.4.tgz
npm http 200 https://registry.npmjs.org/minifyify/-/minifyify-0.4.4.tgz
npm http GET https://registry.npmjs.org/browserify
npm http GET https://github.com/ben-ng/UglifyJS2/archive/sourcemap-offset-fix.tar.gz
npm http GET https://registry.npmjs.org/through
npm http GET https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/concat-stream
npm http GET https://registry.npmjs.org/utilities
npm http GET https://registry.npmjs.org/osenv
npm http GET https://registry.npmjs.org/atob
npm http GET https://registry.npmjs.org/btoa
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/through
npm http 304 https://registry.npmjs.org/source-map
npm http 304 https://registry.npmjs.org/concat-stream
npm http 304 https://registry.npmjs.org/utilities
npm http 304 https://registry.npmjs.org/osenv
npm http 304 https://registry.npmjs.org/atob
npm http 304 https://registry.npmjs.org/btoa
npm http 304 https://registry.npmjs.org/lodash
npm http 404 https://github.com/ben-ng/UglifyJS2/archive/sourcemap-offset-fix.tar.gz
npm ERR! fetch failed https://github.com/ben-ng/UglifyJS2/archive/sourcemap-offset-fix.tar.gz
npm ERR! Error: 404 Not Found
npm ERR!     at WriteStream.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/fetch.js:57:12)
npm ERR!     at WriteStream.EventEmitter.emit (events.js:117:20)
npm ERR!     at fs.js:1596:14
npm ERR!     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:103:5
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.5.0-42-generic
npm ERR! command "node" "/usr/local/bin/npm" "install" "minifyify"
npm ERR! cwd /home/kurttheviking
npm ERR! node -v v0.10.13
npm ERR! npm -v 1.3.7
npm http 200 https://registry.npmjs.org/browserify
npm http GET https://registry.npmjs.org/browserify/-/browserify-2.33.1.tgz
npm http 200 https://registry.npmjs.org/browserify/-/browserify-2.33.1.tgz

Add an option to not mangle names

Since renamed variables don't show up in Chrome's inspector with their original names, there should be an option that skips mangling names to make debugging easier.

LICENSE?

you must add license text for MIT license

Use exorcist to pull out source maps?

I feel like you may have seen this and have opinions on it, just interested to hear them. It seems like it might be a better choice than using a regex to do this:

https://github.com/thlorenz/exorcist

Also want to open up discussion on whether there should be an option to specify an internal or external source map. Right now, if you pass a manual callback, it auto-assumes you want an external source map. Ideally, you'd be able to keep the stream structure and specify this through an additional option (like sourceMapPath or something, and it would drop it internally if undefined`).

Not working with transforms?

Ah, while I thought my problems had been solved, I almost immediately ran into another one. I'm trying to use the coffeeify transform here to load in coffee files, but as soon as I introduce minifyify, another error comes up.

Reproduction code:

# index.coffee
console.log 'wow'
// test.js
var path   = require('path'),
browserify = require('browserify'),
coffeeify  = require('coffeeify'),
minifyify  = require('minifyify');

var b = browserify({ extensions: ['.js', '.json', '.coffee'] });
b.transform(coffeeify)
b.add(path.join(__dirname, 'index.coffee'));
b.bundle({debug: true}).pipe(minifyify()).pipe(process.stdout);

The error I'm getting looks like this:

return cb(new Error('Nothing to optimize. Did you set debug to true, and
             ^
TypeError: undefined is not a function
  at Stream.end (xxx/node_modules/minifyify/lib/index.js:33:14)

If I remove minifyify, it works, and if I change the coffee file to javascript and remove the transform, it works. Thanks again for being so responsive and for your great work on this library!

Using brfs results in parsing error

Since upgrading browserify and minifyify recently I have been unable to minify my source.
Running this gist results in the following error.

https://gist.github.com/tjconcept/4cac79fcacd93b297648

.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:204
    throw new JS_Parse_Error(message, line, col, pos);
          ^
Error
    at new JS_Parse_Error (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:196:18)
    at js_error (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:204:11)
    at croak (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:663:9)
    at token_error (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:671:9)
    at unexpected (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:677:9)
    at expr_atom (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:1161:13)
    at maybe_unary (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:1334:19)
    at expr_ops (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:1369:24)
    at maybe_conditional (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:1374:20)
    at maybe_assign (.../node_modules/minifyify/node_modules/uglify-js/lib/parse.js:1398:20)

minifyify and source maps without sourcesContent

Hi Ben,

I'm trying to use minifyify with source maps without sourcesContent.
I've taken a look into the code and I don't think minifyify support this.

Are you interested at adding this feature into minifyify?
I've a small patch if you are interested.

Alex Man

Peer dependency problem

The peer dependency listed is ~3.30.0. Its giving me a problem when I want to use browserify 3.31.1. Why is the peer dependency such a narrow range? Shouldn't you have ~3?

source maps return the minified source code

This was working in the way I expected last week, but now I get this result in a clean copy of my repo

browserify -d scripts/main.js -p [minifyify --map bundle.map --output scripts/bundle.map] -o scripts/bundle.js

produces minified bundle.js but the mapping gives me minified code in the debugger.
sourcemap

Javascript API broken?

I've got the following error no matter what I do when trying to use minifyify:

result.code = result.code.replace(/\s*\/\/(?:@|#) sourceMappingURL=(.*)$/m
                        ^
TypeError: Cannot read property 'code' of undefined

I tried reproducing this with as minimal of a test case as possible and am still getting the error:

// error-reproduction.js
var browserify = require('browserify'),
    minifyify = require('minifyify');

var b = browserify({files: 'test.js'});
b.bundle().pipe(minifyify()).pipe(process.stdout);
// test.js
console.log('wow');

Love the idea behind this library and would really love to use it - let me know if there's anything I'm stupidly doing wrong or any way I can help resolve this issue!

Convert to real transform?

Ok, so I know this was discussed here quite a number of months ago, but it seems like now this might be possible. For example, uglifyify has a 'global' mode that seems to accomplish what you were after in this issue. Do you still think there are advantages to this type of module rather than a streaming transform?

Add flag to disable sourcemap?

While the sourcemaps are useful in development, you may not always want to carry around a sourcemap in production. Just removing the map file however can lead to stray 404s because the minified source file still has the source map URL in it.

It'd be useful if the source map generation could be disabled just by flipping a switch -- ideally minifyify should just silently not generate a source map if there is no source map in the browserify bundle.

A bit lost with Gulp + Browserify/Watchify + Coffeeify + Minifyify

I get the following error when I try to enable the Minifyify plugin:

[02:43:06] 'browserify' errored after 241 ms Minifyify: opts.output is required since no callback was given

I would like to minify the output of the coffeeify while preserving the source map. The script is adapted from https://github.com/greypants/gulp-starter/blob/master/gulp/tasks/browserify.js.

If I understand properly, I should add a callback to bundler.bundle({debug:true}), but I don't know what to do in it...

browserify   = require 'browserify'
watchify     = require 'watchify'

gulp         = require 'gulp'

source       = require 'vinyl-source-stream'
buffer       = require 'vinyl-buffer'

uglify       = require 'gulp-uglify'
minifyify    = require 'minifyify'

bundleLogger = require '../util/bundleLogger'
handleErrors = require '../util/handleErrors'


gulp.task 'browserify', ->
  bundleMethod = if global.watching then watchify else browserify

  bundler = bundleMethod
    # Specify the entry point of your app
    entries: ['./client/js/main.coffee'],
    # Add file extentions to make optional in your requires
    extensions: ['.coffee'],
    debug: !global.production

  bundler.transform("coffeeify")#!!global.production ? "coffeeify/no-debug" : "coffeeify")
  bundler.plugin('minifyify')

  bundle = ->
    # Log when bundling starts
    bundleLogger.start()

    bundler
      # Enable source maps!
      .bundle({debug:true})
      # Report compile errors
      .on('error', handleErrors)
      # Use vinyl-source-stream to make the
      # stream gulp compatible. Specifiy the
      # desired output filename here.
      .pipe(source 'app.js')

      # This works, but eats the source map.
      # .pipe(buffer())
      # .pipe(uglify())

      # Specify the output destination
      .pipe(gulp.dest './static/scripts')
      # Log when bundling completes!
      .on('end', bundleLogger.end)

  if global.watching
    # Rebundle with watchify on changes.
    bundler.on 'update', bundle


  bundle()

Edit: I should probably add that Coffeeify inlines the source map at the end of the bundle.

Store the source map in an independent file

I have been seeying some issues regarding to the minimified size, maybe I'm doing something wrong...

browserify standalone + uglify

total 108K
-rw-r--r-- 1 piranna piranna 54K dic 3 12:33 kws-content-api.js
-rw-r--r-- 1 piranna piranna 28K dic 3 12:33 kws-content-api.map
-rw-r--r-- 1 piranna piranna 21K dic 3 12:33 kws-content-api.min.js

browserify standalone debug + uglify

total 176K
-rw-r--r-- 1 piranna piranna 143K dic 3 12:36 kws-content-api_debug.js
-rw-r--r-- 1 piranna piranna 29K dic 3 12:38 kws-content-api_debug.min.js

browserify standalone debug + minifyify

total 280K
-rw-r--r-- 1 piranna piranna 143K dic 3 12:41 kws-content-api_debug.js
-rw-r--r-- 1 piranna piranna 133K dic 3 12:41 kws-content-api_debug.min.js

Why the minified version created with minifyify is so big? I supose is because it has inline not only the source map file but also the original source files (the base64 url is fairly big). I find it really useful to have the orginal source files embebed on the source map, but could it be posible to add an option to store the map in an independent file, as uglify does by default? This way the minified file wouldn't be so big...

Issue with bundle() that no longer accepts option arguments

I get

node_modules/gulp/node_modules/orchestrator/index.js:153
            throw err;
                  ^
Error: bundle() no longer accepts option arguments.
Move all option arguments to the browserify() constructor.

although I don`t pass arguments to bundle();

gulp.task('build', function() {
var b = new browserify();

        b.add('./main.js');

        b.plugin('minifyify', {
            map: false,
            minify: false,
            output: './bundle.map.js'
        });

        b.bundle();
})

Plans for 0.5.x

Now that a few key browserify and uglify issues have been identified and resolved, I think that it might be worth rewriting minifyify to process browserified bundles instead of hooking into the bundling process itself. Not only is this going to be faster and less error prone, it's also a lot simpler and makes for a much nicer API than the current mess.

Not work at all

So begin.
Project:
/lib/a.js:/lib/b.js:/lib/c.js
exports.a=1;
exports.b=2;
/index.js
exports.a = {
a: require("./lib/a.js"),
b: require("./lib/b.js"),
c: require("./lib/c.js")
};

Build:
browserify index.js -s glb > out.js

Run in browser.
console.log(JSON.stringify(window.glb));
Output:
{"a":{"a":{"a":1,"b":2},"b":{"a":1,"b":2},"c":{"a":1,"b":2}}}

Build with minify:
browserify index.js -p [minifyify --map bundle.map.json --output bundle.map.json] > out4.js

Run in browser.
console.log(JSON.stringify(window.glb));
Output:
undefined

Add output option to configuration

Readme says:

The --output option is a required option unique to the command line interface and specifies where minifyify should write the sourcemap to on disk.

I've changed my Gruntfile so I can use minifyify as a browserify plugin instead of using a hand-made grunt plugin and it works as a charm, but... where is the map file?!?!? I think this output option should be added, so you can specify its location programatically instead of needing to write it yourself by hand (where, in my case, it's impossible...).

minifyify+browserify-shim#3.6.0 breaks source maps

I will update this ticket with a better description as I am able to better track down what's happening but upgrading browserify-shim from 3.5.0 -> 3.6.0 causes source maps to break. When trying to set a breakpoint on a line it just falls to the end of the file as if the ref pointers are all wrong.

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.