Ken Tapdasan
Ken Tapdasan

Reputation: 41

Uglify and Minify AngularJS Source Code without NodeJS

I want to uglify then minify my AngularJS source codes. I have been searching for samples then I found grunt but grunt needs NodeJS our website does not run with NodeJS.

I can't find any good alternatives.

Any ideas?

Upvotes: 2

Views: 963

Answers (2)

shaunhusain
shaunhusain

Reputation: 19748

To clear some things up I'm showing what "grunt" is on my development machine below:

shaun@laptop:~/.npm$ which grunt
/home/shaun/local/bin/grunt

shaun@laptop:~/.npm$ ls -al /home/shaun/local/bin/grunt
lrwxrwxrwx 1 shaun shaun 39 Apr 15  2015 /home/shaun/local/bin/grunt -> ../lib/node_modules/grunt-cli/bin/grunt

shaun@laptop:~/.npm$ cat /home/shaun/local/lib/node_modules/grunt-cli/bin/grunt 
#!/usr/bin/env node

'use strict';

process.title = 'grunt';

// Especially badass external libs.
var findup = require('findup-sync');
var resolve = require('resolve').sync;

// Internal libs.
var options = require('../lib/cli').options;
var completion = require('../lib/completion');
var info = require('../lib/info');
var path = require('path');


var basedir = process.cwd();
var gruntpath;

// Do stuff based on CLI options.
if ('completion' in options) {
  completion.print(options.completion);
} else if (options.version) {
  info.version();
} else if (options.base && !options.gruntfile) {
  basedir = path.resolve(options.base);
} else if (options.gruntfile) {
  basedir = path.resolve(path.dirname(options.gruntfile));
}

try {
  gruntpath = resolve('grunt', {basedir: basedir});
} catch (ex) {
  gruntpath = findup('lib/grunt.js');
  // No grunt install found!
  if (!gruntpath) {
    if (options.version) { process.exit(); }
    if (options.help) { info.help(); }
    info.fatal('Unable to find local grunt.', 99);
  }
}

// Everything looks good. Require local grunt and run it.
require(gruntpath).cli();

As you can see Grunt is a node script so it does require node to run a grunt based plugin. That said you can just download and run any node script from github or wherever, they are just JS files.

https://github.com/mishoo/UglifyJS2

^^ if you were to clone the above repository and had node installed you could just run

git clone https://github.com/mishoo/UglifyJS2.git
cd UglifyJS2
bin/uglify -m -- /full/path/to/input.js
# note the above assumes you already have node installed on the
# development machine since the bin/uglify file is interpreted/run
# by node VM

This will output the mangled js which you can then put on the server (without node at all). To reiterate your build process/tools don't need to be installed on the server (probably shouldn't be ideally).

Upvotes: 0

Big Yang
Big Yang

Reputation: 56

Uglify code is only needed when you want to publish your code. The server doesn't need it, because it doesn't take into account spaces in code.

Upvotes: 1

Related Questions