0

My JavaScript library is getting fairly large and slow to compile with Closure. I'd like to create a makefile that compiles only changed modules. However I'd still like to use ADVANCED_OPTIMIZATIONS to rename module contents for size and security reasons, also those functions that are called from other modules. Is there a reasonable way to do this?

Basically I'd like to compile module A and store somewhere the mapping from actual class member names to minified versions. Then when compiling module B, it should translate the code accessing module A to use the correct minified names, as it would if I compiled the whole thing at once.

jjrv
  • 4,211
  • 2
  • 40
  • 54
  • 1
    This will not be optimal, as you'd need to "export" all the library functions (since Closure won't know which ones are used for other files). You won't get dead code removal -- a highly desirable feature. You can use the generated variable mapping files to force the same renaming. However, my suggestion is to get a fast CPU... – Stephen Chung Apr 26 '12 at 02:29
  • Is there a way to use the generated variable mapping files without writing new tools to do it? – jjrv Apr 26 '12 at 19:26
  • 1
    Yes, I believe there is a command line option to use existing variable mapping files so that renamings are consistent from run to run. – Stephen Chung Apr 28 '12 at 02:14
  • Thanks! I didn't realize the power of --variable_map_input_file and --property_map_input_file. They also allowed some other tricks I've always wanted to do. – jjrv Apr 29 '12 at 21:01
  • Be careful when using the variable and property maps, there isn't necessarily a 1 to 1 mapping and they don't prevent dead code removal, inlining etc which is essential to separate compilation. – John May 04 '12 at 20:13

1 Answers1

1

Ultimately, you can't get global dead code removal and separate compilation. You have to export an interface of some kind in a way that lets the compiler know that you have an external use of the code you want to keep.

John
  • 5,443
  • 15
  • 21