2

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?

6
  • 3
    The most popular JavaScript minifiers and uglifiers are written in JavaScript, and must be run using NodeJS. Just to clarify, you're aware that uglify/minify (and all other build steps) are run one time, on the developer's computer, not the server, correct? This means the developer's computer must have NodeJS, not the server. Commented Jan 11, 2018 at 2:04
  • Hi @Sidney yes I am aware. Commented Jan 11, 2018 at 2:06
  • @KenTapdasan not sure we follow.. you install node on your development computer, run the minification, and put the output on your server. Closure Compiler uses Java, but that's a whole 'nother beast. Commented Jan 11, 2018 at 3:06
  • if not nodejs, then what it is running with - please clarify that.. Commented Jan 11, 2018 at 3:36
  • Correction: grunt does not need nodejs at all. Sure grunt uses npm but that has nothing to do with your production server. Commented Jan 11, 2018 at 5:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@Rabbid76 this actually does point closer to an answer, based on the OPs comments they are not understanding that you can run the uglification scripts with any given technology and not be actively running that technology on the server, which is what this answer says.
Thank you for the answer. I want to uglify and minify it on the development machine then and put the output to our server do you have basic instructions how? I'm a newbie sorry I can't much understand super complex codes.
@Ken Tapdasan yes, you can use cli,take a look at link
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.