Using Plovr to remove whitespace from simple javascript file without managing dependencies

278 Views Asked by At

I can't figure out how to get Plovr to just remove whitespace from a simple javascript file and not try to manage dependencies or scopes. (I don't want to use ADVANCED mode if I can help it because my needs for this file are extremely simple and I don't want to have to define externs to preserve every variable name.) I've combed through the Plovr documentation but I still can't figure out what I'm doing wrong.

hello.js:

alert("Hello world");

hello-config.js:

{
  "id": "hello",
  "mode": "WHITESPACE_ONLY",
  "level": "QUIET",
  "inputs": "./hello.js",
  "output-file": "./hello-compiled.js"
}

When I run java -jar ./plovr.jar build hello-config.js, the output in hello-compiled.js is not one line as I'd expect. Instead it's 21 lines long with lots of stuff like this:

hello-compiled.js:

var COMPILED=!0,goog=goog||{};goog.NODE_JS=!1;goog.global=goog.NODE_JS?eval("global"):this;goog.DEBUG=!0;goog.LOCALE="en";
goog.addDependency=function(a,b,c){if(!COMPILED){for(var d,a=a.replace(/\\/g,"/")
goog.scope=function(a){a.call(goog.global)};
3

There are 3 best solutions below

0
On

You need to install python and java, and make sure it is running properly. Inside closureCompiler folder, which is in parallel to closure folder, add plovr-81ed862.jar

Config file

{
    "id": "hello",
        "inputs": "hello.js",
        "output-file": "hello-compiled.js"
}

Create Batch File plovr-build.bat and include following lines

java -jar .\closureCompiler\plovr-81ed862.jar build .\hello-config.js
pause

create another batch-file, plovr-serve and add following lines

java -jar .\closureCompiler\plovr-81ed862.jar serve .\hello-config.js
pause

Keep these two batch files and hello-config.js parallel to folder closure and closurecompiler

Then you are ready to go. Run the build and after that run the plovr-serve. Now open your application.html. Don't close the plovr-serve window.

0
On

Plovr is adding the Closure Library "base.js". You can avoid this by setting:

"experimental-exclude-closure-library":true

As discussed here: https://groups.google.com/forum/?fromgroups=#!topic/plovr/AEvvn8wST2A

0
On

Use "mode": "WHITESPACE",

Because Plovr does not recognize "mode": "WHITESPACE_ONLY", and uses default mode.

Read http://plovr.com/docs.html section "More on Config Files" for correct mode types.