Giter Club home page Giter Club logo

Comments (3)

gaearon avatar gaearon commented on May 5, 2024

Personally when I had this kind of task, I just walked over tons of modules and manually reformatted them to be in CommonJS. I'd replace some common patterns via "find and replace" but it was mostly manual work.

from ama.

STRML avatar STRML commented on May 5, 2024

@winterbe See also exports-loader, which can fix this kind of issue and prevent the leak to global. If most of your modules follow a similar style, you can apply a loader to all of them and fix the issue in your bundle.

This code will create a local variable called window in the module's scope and set it to an empty object so your module is unable to actually export to global. Then, it will add module.exports = window.MyModule to the module so you can use it like a proper commonjs module.

require("imports?window=>{}!exports?window.MyModule!./file.js")

From http://webpack.github.io/docs/shimming-modules.html

from ama.

winterbe avatar winterbe commented on May 5, 2024

Thanks for pointing that out. I'll give it a shot.

Am 17.09.2015 um 00:19 schrieb Samuel Reed [email protected]:

@winterbe See also exports-loader, which can fix this kind of issue and prevent the leak to global. If most of your modules follow a similar style, you can apply a loader to all of them and fix the issue in your bundle.

This code will create a local variable called window in the module's scope and set it to an empty object so your module is unable to actually export to global. Then, it will add module.exports = window.MyModule to the module so you can use it like a proper commonjs module.

require("imports?window=>{}!exports?window.MyModule!./file.js")


Reply to this email directly or view it on GitHub.

from ama.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.