0

I'm trying to import the Politespace library into a Webpack project. It's written such that on a certain line it tries to attach a global Politespace object to the window object, which is needed for an event listener on the document object to correctly behave.

But when trying to load this in Webpack by putting an import into vendor.js I'm seeing that w comes out as just an object - it seems like Webpack is substituting a different variable, so that it's never attached to the window.

Is there a way to allow importing libraries that assign global properties to Window, other than having to copy and paste the file and modify it to refer specifically to the window rather than w (which I've verified does work)?

1 Answer 1

2

You can do that by using the imports-loader

You can use it in 2 ways; either when you require() the library by doing something like

require("imports-loader?this=>window!politespace");

or by setting it up in the webpack.config.js like so (as per documentation)

module.exports = {
    ...
    module: {
        loaders: [
            {
                test: require.resolve("some-module"),
                loader: "imports-loader?this=>window"
            }
        ]
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.