Search code examples
gruntjsgrunt-contrib-uglify

Grunt Uglify returning different minified code from multiple developers


When I uglify my code my machine produces a different minified version of javascript than another developer. Both of our minified code is correct but it is slightly different.

For Example:

-            }) : (a.visible = !1, a.videoCss = b > d ? "hideLeft" : "hideRight");
+            }) : (a.visible = !1, b > d ? a.videoCss = "hideLeft" : a.videoCss = "hideRight");

Verified that we are both using the same version of Grunt Uglify: "version": "0.6.0".


Solution

  • I've ran into this problem before. Remember that your package.json file will specify what version of grunt-contrib-uglify to use; but grunt-contrib-uglify has it's own dependencies. It's possible that you have inconsistent versions of uglify-js. To check this, in the root of the project (where the package.json file is) type:

    npm list | grep 'uglify'

    The output should look like:

    ├─┬ [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    

    A technique for locking down the sub dependencies of your top level dependencies is by using npm shrinkwrap. This will generate a file called npm-shrinkwrap.json which recursively scans your node_modules directory and defines dependencies and sub-dependencies and their specific versions. In your case, the command will probably look like

    npm shrinkwrap --dev

    Now, when someone else runs npm install - they should get the same versions for each dependency and its sub-dependencies.