Using the --module option in Closure Compiler to create multiple output files

后端 未结 1 1922
小蘑菇
小蘑菇 2020-12-08 01:27

I\'m creating a fairly large library of JavaScript, using Closure Compiler for both its wonderful compression as well as the type-checking and warning systems.

I wan

1条回答
  •  北海茫月
    2020-12-08 01:54

    java -jar compiler.jar ^
    --chunk jq:1: --js jquery-1.6.2.js ^
    --chunk t:1:jq: --js test.js ^
    --compilation_level ADVANCED_OPTIMIZATIONS
    

    This example will compile out 2 files for you:

    • jq.js
    • t.js

    jq.js will be jquery 1.6.2 with advanced minification, and t.js will use that minified version of JQuery properly.

    I wish there was a JavaFiddle I could post this to to demonstrate it.


    Older version

    This original answer was for an older version of Closure Compiler. I've left it intact below in case you're in an environment that needs to keep the older version in place.

    How to handle multiple output files, aka modules: http://groups.google.com/group/closure-compiler-discuss/browse_thread/thread/ec7f6809b19b019e/25a94f3994173840

    Copy/pasting:

    java -jar Build\Tools\compiler.jar ^ 
    --compilation_level=ADVANCED_OPTIMIZATIONS ^ 
    --externs Build\jQuery.externs.js ^ 
    --js Build\Output\Compiling.js ^ 
    --js Script/Themes.lang.js ^ 
    --js Script/Themes.js ^ 
    --module Core:3 ^ 
    --js UI/ThemeChooser/ThemeChooser_en.htm.js ^ 
    --js UI/ThemeChooser/ThemeChooser.js ^ 
    --module UI_ThemeChooser:2:Core ^ 
    --js UI/VerticalTabs/VerticalTabs_en.htm.js ^ 
    --js UI/VerticalTabs/VerticalTabs.js ^ 
    --module UI_VerticalTabs:2:Core ^ 
    --js Pager/Pager_en.htm.js ^ 
    --js Pager/jquery.Pager.js ^ 
    --js Pager/Pager.js ^ 
    --module Pager:3:VerticalTabs ^ 
    --module_output_path_prefix .\Compiled\ 
    

    And as he notes, --js_output_file is irrelevant when outputting modules.

    Note: Apparently the Closure Compiler has changed the arg "--module" to "--chunk". An editor suggested the change; for the newer version I kept the change, for the older version I kept the older argument name, since there are always people out there using older versions of build tools, and that kind of small breaking change can really screw ya up.

    0 讨论(0)
提交回复
热议问题