Code Monkey home page Code Monkey logo

Comments (34)

byrichardpowell avatar byrichardpowell commented on May 12, 2024 2

I have also run into this problem using Rickshaw with require and the r.js optimiser. I bypassed the problem by changing the r.js build script to use:

uglify2: {
     mangle: false
},
optimize: "uglify2"

Which is a less agressive minification. Its a shame to do this but Rickshaw is still an awesome piece of code.

from rickshaw.

jzaefferer avatar jzaefferer commented on May 12, 2024 1

This works:

uglify: {
    except: ["$super"]
}

Still a rather big PITA...

from rickshaw.

cstephe avatar cstephe commented on May 12, 2024 1

Using: "grunt-contrib-uglify": "~0.2.0"
I applied this.

uglify: {
            options: {
                mangle: {
                    except: ["$super"]
                }
            }
        }

from rickshaw.

dchester avatar dchester commented on May 12, 2024

If you look in Makefile you can see we're running uglify with a --reserved-names flag to tell it not to clobber the $super special variable name that PTClass uses to facilitate inheritance. Maybe give that a try? Here's what we end up running for a standard build:

uglifyjs --reserved-names "\$super" rickshaw.js > rickshaw.min.js

from rickshaw.

jzaefferer avatar jzaefferer commented on May 12, 2024

Any chance you can get rid of the $super dependency on your side? That reserved-names option only exists in the uglify CLI interface, there's no way to specify that when using uglify directly, or in my case, through other libs like requirejs/r.js.

from rickshaw.

dchester avatar dchester commented on May 12, 2024

Unless we hear that this is a recurring pain point across lots of projects, it's unlikely that we'll move away from using Prototype's class system and $super to facilitate inheritance.

It looks like you can specify variable names to leave alone outside of uglify's CLI interface. The --reserved-names option just proxies through to the except parameter of ast_mangle().

Looks like r.js is pretty configurable too, so I bet there's a way.

from rickshaw.

dchester avatar dchester commented on May 12, 2024

Glad you got this working. Thanks for following up!

from rickshaw.

chrisnicola avatar chrisnicola commented on May 12, 2024

Ran into this myself. I feel it is a rather big pain point, in that it was hard to lock down the reason for it and I lost a fair bit of time to it (not easy to debug minified code). Any time there is potential inconsistency between the regular and minified version I think it should try to be fixed if at all possible.

With that small complaint out of the way, I still think this library is freakin' awesome.

from rickshaw.

drock avatar drock commented on May 12, 2024

I have run into this problem when using Rickshaw + RequireJS as well

from rickshaw.

mieky avatar mieky commented on May 12, 2024

Just got bitten by this. Finding the solution here saved so much time, thanks @jzaefferer.

from rickshaw.

estk avatar estk commented on May 12, 2024

This issue means that Rickshaw will not work with a meteor.js app run in production mode. I opened an issue on meteor here: meteor/meteor#1360.

from rickshaw.

rlora avatar rlora commented on May 12, 2024

Ran into the issue on a meteor app in production :(
@estk did you find a workaround not involving changing meteor source?

from rickshaw.

rcrichton avatar rcrichton commented on May 12, 2024

I've run into this as well. I'm trying to include Rickshaw in a yeoman scaffolded app using the angular generator. When it is minified by grunt I get the same issue mentioned here. Does anyone know how to get around this?

from rickshaw.

jzaefferer avatar jzaefferer commented on May 12, 2024

@rcrichton include this somewhere in your configuration:

uglify: {
    except: ["$super"]
}

Since this issue is a recurring pain I'm going to reopen it.

from rickshaw.

srlm-io avatar srlm-io commented on May 12, 2024

@jzaefferer 's solution works for me in Node as well:

        var requirejs = require('requirejs');
        requirejs.optimize({
            appDir: '...',
            dir: '...',
            uglify: {
                except: ["$super"] // Don't modify the "$super" text, needed to make Rickshaw pass optimization.
            }
        },
        function(err) {
        });

from rickshaw.

rcrichton avatar rcrichton commented on May 12, 2024

Thanks @cstephe that worked for me to.

from rickshaw.

ronnyle avatar ronnyle commented on May 12, 2024

it seems this has people loosing hair for two years now :)
thanks @jzaefferer and +1 to solve this...

from rickshaw.

wshaver avatar wshaver commented on May 12, 2024

Still having this issue.

from rickshaw.

wshaver avatar wshaver commented on May 12, 2024

Could this be added to the readme at least? A note about uglify and this project?

from rickshaw.

wshaver avatar wshaver commented on May 12, 2024

Awesome, thanks much! Hopefully that'll save the next programmer some frustrating hours trying to read the minified file.

from rickshaw.

mastersingh24 avatar mastersingh24 commented on May 12, 2024

It definitely saved me

from rickshaw.

ShimiSun avatar ShimiSun commented on May 12, 2024

Can you please unsubscribe me from the mailing list?

I tried to unsubscribe my self but it is not working apparently

Thanks

Sent from my iPhone

-Shimi

On 16 בספט 2014, at 17:45, mastersingh24 [email protected] wrote:

It definitely saved me


Reply to this email directly or view it on GitHub.

from rickshaw.

petulal avatar petulal commented on May 12, 2024

Thanks @cstephe your solution worked for me!

from rickshaw.

metakermit avatar metakermit commented on May 12, 2024

I can confirm that this is a pain point using the basic Yeoman web app template as well - the usemin step minimises the library as well and I really don't know how to add an exception there. Anyone maybe knows?

from rickshaw.

willsu avatar willsu commented on May 12, 2024

@jzaefferer Your suggestion worked for me.. Many more years later! Thanks a lot. I'm glad I found this issue before spending my entire day on this problem.

FWIW, I was not using rickshaw. I was using gulp-uglify 1.0.2 with prototypejs 1.7.2, but the fundamental issue still stands.

For historical purposes, I'd like to share some more technical details on why @jzaefferer 's fix solves the problem:

Prototype has an implicit dependency on arguments in the 0th position of a function call that are are named '$super' that have been created with the Class.create method. It is silly, IMHO, to have technical dependencies on an 'argument name' in any function in any language (let alone JavaScript). JS minifiers, like Uglifyjs, cannot reasonable detect this dependency when their algorithms are run against a static file.

This is the offending bit of Prototype code (from the Class -> addMethods function):

if (ancestor && Object.isFunction(value) &&
          value.argumentNames()[0] == "$super") {

I don't know a JS minifier (in it's right mind) that would replace that "$super" String reference with the modified argument in a function caller (which also should not have to be standardized anyway..).. And really it shouldn't.

Thanks again to those who contributed to this thread!

from rickshaw.

metakermit avatar metakermit commented on May 12, 2024

Tried different exclude options, but none of them worked. In the end I had to disable usemin's minification for JavaScript like this:

        useminPrepare: {
            options: {
                dest: '<%= config.dist %>',
                flow: {
                    html: {
                        steps: {'js': ['concat'], 'css': ['concat', 'cssmin']},
                        post: {}
                    }
                }
            },
            html: '<%= config.app %>/index.html'
        },

I don't see this as a good solution, though - dependency management and build systems in JavaScript are complicated enough even without having to customize them specifically for individual libraries.

from rickshaw.

glenpike avatar glenpike commented on May 12, 2024

👍 Thanks @jzaefferer for this one, luckily it comes up in a bug search so I didn't have to spend ages looking for the problem. Pity the owners "won't fix" this issue, but I can understand it's sort of someone elses mess.

from rickshaw.

glenpike avatar glenpike commented on May 12, 2024

In addition to @byrichardpowell's comment, you can still mangle with uglify2 and the following config:

uglify2: {
    mangle: {
        except: ['$super']
    }
},
optimize: 'uglify2'

from rickshaw.

agwidarsito avatar agwidarsito commented on May 12, 2024

I'll add to the growing list of people who have been bitten by this. Adding a note to the readme is a good start, although I feel this should be somewhere more visible too (if possible?)

Useful link: https://www.symphonious.net/2013/09/13/uglifyuglify2-rickshaw-requirejs-and-minification/

from rickshaw.

gintsgints avatar gintsgints commented on May 12, 2024

Solution for gulp:

.pipe($.uglify({ mangle: {except: '$super'} ,preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))

from rickshaw.

ceremcem avatar ceremcem commented on May 12, 2024

For those who use gulp with gulp-if-else is as follows:

For uglify:

var myUglify;
myUglify = function(x){
  return uglify({
    mangle: {
      except: ['$super']
    }
  }, x);
};

For uglify-es:

var myUglify;
myUglify = function(x){
  return uglify({mangle: true}, x);
};

Then replace uglify with myUglify:

        .pipe(ifElse(onlyCompile, myUglify))

from rickshaw.

conanza avatar conanza commented on May 12, 2024

Running into this issue when using Rickshaw with Angular 5. When built for production, $super is being mangled.

Angular-cli seems stiff and mostly unconfigurable. In most threads I've seen, Angular-cli team is not trying to support specifying of uglify options via cli or config.

from rickshaw.

qcgm1978 avatar qcgm1978 commented on May 12, 2024

Meet a project built with wake and it works when "minify": false, set.:)

from rickshaw.

rei-ber avatar rei-ber commented on May 12, 2024

for webpackv5 and terser I used this config:

optimization: {
    minimizer: [new TerserPlugin({
        terserOptions: {
            mangle: {
                reserved: ['$super']
            }
        }
    })],
},

from rickshaw.

Related Issues (20)

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.