Skip to content

wrapShim config #623

Closed
Closed
@jrburke

Description

@jrburke

A built file with shim config can fail if it has an intermediate dependency that is an AMD module but downstream dependencies are not AMD.

Canonical example: Backbone depends on jQuery and Underscore. jQuery and Underscore do not have any dependencies, so they can also export a global value when they run, and only call define() at the end with the global they set up.

However, Backbone needs jQuery and Underscore loaded before its main module body can execute. So it is not executed right away, it is executed once the dependencies have had their define()'d factories called.

But if there is a shim config for something that depends on Backbone, that shimmed dependency wants Backbone available immediately when it executes, and it does not have a define() wrapper.

Before a build, this all works because the shimmed dep is not fetched until Backbone is fully defined. However, in a build, with all the dependencies inlined, there will be a failure.

A way to avoid this is to wrap the shimmed dependency in a define() call -- this avoids executing it until its dependencies are available.

I have traditionally avoided this because by wrapping, it changes the scope for the shimmed dependency. If that dependency is doing a var A = {} to define a global A, inside a define() wrapping that will not be true. Plus shim is a crutch, an intermediary step to full modularization. But hey, the peoples like to use shim, and some like to even use Backbone.

So allow shimmed scripts to be wrapped, and try to mitigate the wrapping effects. For the var A = {} case, if the shim config configures exports: 'A', then go ahead and assign that as a global a part of this wrapping.

So wrapShim: true will enable the wrapping behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy