19

I am looking for a way to prevent r.js (RequireJS' optimization script) from ugylyfying our JS-modules to maintain readability for debugging purposes. I expect the script (running on Node.js by the way) to have some command line option to be passed. Unfortunately, the documentation if this tool is rather poor.

Leo Selig
  • 1,062
  • 1
  • 16
  • 30

1 Answers1

37

Pass optimize=none on the command line to r.js, or include optimize: "none" in your build script.

eg:

({
    baseUrl: ".",
    paths: {
        jquery: "some/other/jquery"
    },
    name: "main",
    out: "main-built.js",
    optimize: "none"
})

See http://requirejs.org/docs/optimization.html for more information.

If you check the source, you will see that the default is set to "uglify". Here are the options which are accepted:

  • uglify: (default) uses UglifyJS to minify the code.
  • uglify2: in version 2.1.2+. Uses UglifyJS2.
  • closure: uses Google's Closure Compiler in simple optimization mode to minify the code. Only available if running the optimizer using Java.
  • closure.keepLines: Same as closure option, but keeps line returns in the minified files.
  • none: no minification will be performed.
minikomi
  • 8,363
  • 3
  • 44
  • 51
  • Although it seems to ignore the command line argument but when I add it in the build-json it works fine – Leo Selig Mar 18 '13 at 07:27
  • 4
    The command line argument is supposed to be `optimize=none`, instead of `--optimize=none` (which should show up as an edit soon in the post) – Saif Hakim Dec 17 '13 at 23:57