How to host the google libphonenumber locally?

后端 未结 3 1441
盖世英雄少女心
盖世英雄少女心 2020-12-28 21:40

During development on my localhost, I am trying to self host the libphonenumber library. I am trying with the following:



        
相关标签:
3条回答
  • 2020-12-28 22:09

    You may have solved this already, but I found a really easy way to compile all the libphonenumber code into one file that includes closure library stuff.

    Go to http://closure-compiler.appspot.com/home

    This is Google's online version of the closure compiler.

    Then input something like:

    // ==ClosureCompiler==
    // @compilation_level SIMPLE_OPTIMIZATIONS
    // @output_file_name libphonenumber.js
    // @use_closure_library true
    // @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonemetadata.pb.js
    // @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonenumber.pb.js
    // @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/metadata.js
    // @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonenumberutil.js
    // @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/asyoutypeformatter.js
    // @formatting pretty_print
    // ==/ClosureCompiler==
    

    You can add or delete any extra files you want.

    Then click Compile.

    This will retrieve each of the latest files from the repository and build it into a single javascript file.

    Now you don't need to worry about handling all the closure library code, as what you will need has already been compiled in.

    Hope this helps.

    Edit: I find that this is really useful for handling updates to the library as well. If you just rerun this in the compiler, you will get your new javascript file with all the latest updates.

    0 讨论(0)
  • 2020-12-28 22:22

    Since google moved their code to github the process has changed, if only a little bit:

    1) go to http://closure-compiler.appspot.com/home

    2) insert the following

    // ==ClosureCompiler==
    // @compilation_level SIMPLE_OPTIMIZATIONS
    // @output_file_name libphonenumber.js
    // @use_closure_library true
    // @code_url https://github.com/googlei18n/libphonenumber/raw/master/javascript/i18n/phonenumbers/phonemetadata.pb.js
    // @code_url https://github.com/googlei18n/libphonenumber/raw/master/javascript/i18n/phonenumbers/phonenumber.pb.js
    // @code_url https://github.com/googlei18n/libphonenumber/raw/master/javascript/i18n/phonenumbers/metadata.js
    // @code_url https://github.com/googlei18n/libphonenumber/raw/master/javascript/i18n/phonenumbers/phonenumberutil.js
    // @code_url https://github.com/googlei18n/libphonenumber/raw/master/javascript/i18n/phonenumbers/asyoutypeformatter.js
    // @formatting pretty_print
    // ==/ClosureCompiler==
    

    3) Click Compile

    4) Done: The current compiled libphonenumber.js file should appear in the RHS panel

    0 讨论(0)
  • 2020-12-28 22:32

    May I suggest you check out this vanilla javascript port of the library: https://github.com/halt-hammerzeit/libphonenumber-js/

    It lightweight and can be bundled with Webpack and stuff

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