How do I access the global object (window) using webpack?

后端 未结 3 1371
说谎
说谎 2021-02-12 14:34

I\'m trying to interface ActionScript with JavaScript using ExternalInterface and webpack.

ExternalInterface can only provoked (call

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 15:02

    Aren't you using webpack-dev-server?

    Because when I try webpack command everything is working fine. I'm testing it by typing window.mySampleGlobalVariable in chrome developer tools.

    BUT when I run webpack-dev-server command then my window variable is undefined.

    I have this sample app:

    app.js

    window.mySampleGlobalVariable = 'TEST';
    console.log('App is ready');
    

    index.html

    
    
    
        
            
            Webpack test
        
    
        
            Webpack test
            
        
    
    
    

    webpack.config.js

    var path = require('path');
    
    module.exports = {
        entry: './app.js',
        output: {
            filename: './bundle.js'
        },
        resolve: {
            extensions: ['', '.js']
        }
    };
    

提交回复
热议问题