4

I need to use google-closure-library so I installed this package via npm and put piece of code below (from here) in my webpack (version 3.6.0) config file:

module: {
    rules: [
        {
            test: /google-closure-library\/closure\/goog\/base/,
            use: [
                'imports-loader?this=>{goog:{}}&goog=>this.goog',
                'exports-loader?goog',
            ],
         },
    ],
},
plugins: [
    new webpack.ProvidePlugin({
        goog: 'google-closure-library/closure/goog/base',
    }),
]

If I understand correctly, now I should have access to goog object and its methods in all files (which is provided by ProvidePlugin). The problem is that files which require goog.provide function return error "goog.provide is not a function" and the console.log(goog) returns object which doesn't have any methods of original goog:

{goog: {…}, COMPILED: false}
COMPILED:false
goog:
    DEBUG:true
    DISALLOW_TEST_ONLY_CODE:false
    ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING:false
    ENABLE_DEBUG_LOADER:true
    LOAD_MODULE_USING_EVAL:true
    LOCALE:"en"
    SEAL_MODULE_EXPORTS:{}
    STRICT_MODE_COMPATIBLE:false
    TRANSPILE:"detect"
    TRANSPILER:"transpile.js"
    TRUSTED_SITE:true
defineClass:{SEAL_CLASS_INSTANCES: {…}}

The only way I got it (kind of) working was to export goog from closure-library base.js file and importing it into desired file- but this method requires a lot of changes in all files.

What am I missing? How can I access goog methods?

(I also use VueJS, may it be the problem?)

Marcie
  • 41
  • 2

0 Answers0