Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Globals/Shim for accessing exports of a global variable #1227

Closed
jglover opened this issue Apr 27, 2018 · 7 comments
Closed

Globals/Shim for accessing exports of a global variable #1227

jglover opened this issue Apr 27, 2018 · 7 comments

Comments

@jglover
Copy link

jglover commented Apr 27, 2018

Hi, just looking for some advice re: globals.
I have a private module which has a few exports, which is on window under a variable name (I can't change this). Essentially window.externalModules.* need to map to window.*
In webpack the following would work:

externals: {
    exportOne: 'externalModules.exportOne',
    exportTwo: 'externalModules.exportTwo',
    blah: 'externalModules.blah'
},

The docs seem to suggest this can be done, but despite my efforts with dot syntax, array syntax, and setting handlers or wildcard as per the following I don't seem to be able to get it to work. Another point of note is the module I'm referring too doesn't exist in the node_modules directory in the same directory as homeDir or fuse.js but a node_modules directory one directory down. The docs I'm referring to are:

You can also expose your package's exports to window or exports.


FuseBox.init({
    // exposes window.superHandler
    globals: { "mySuperLib": { "handler": "superHandler"} },

    // OR
    // exposes window.handler and window.logger
    globals: { "mySuperLib": "*" },
})```

what I have currently is:

globals: {
    "@moduleName/subName": "*",

Which contains an index.js with the exports.

Much appreciate any advice on this one.

@jpike88
Copy link
Contributor

jpike88 commented Apr 27, 2018

Can you post your actual fuse.js?

@nchanged
Copy link
Contributor

@jglover Hi
The easiest way to make it work is to expose you entry point instead.

index.js

export * as foobar from "@moduleName/subName"
globals: { "default": "*" }

Then window.fooobar should contain it all.

@jglover
Copy link
Author

jglover commented Apr 27, 2018

Thanks all
@jpike88 there's nothing special about it, literally just started and I'm trying to get an initial bundle and globals working correctly.

@nchanged that would be ideal but I can't change index.js, it's transpiled from another language to js. They're already exported to a variable on window. However @moduleName/subName/index.js does have the four exports I need within it. In theory I could go:

globals: {
  "@moduleName/subName": { "handler": "exportOne"}
}

But I get an error that module @moduleName/undefined could not be found at runtime

@nchanged
Copy link
Contributor

Can you reproduce it?

@jglover
Copy link
Author

jglover commented Apr 27, 2018

Apologies for the slow reply, now I'm getting
Uncaught Package not found @moduleName/subName zen-observable@0.6.1:513
in the Chrome console.
I have verified that the module does exist in the node_modules adjacent to the fuse.js and there's a valid index.js under ./node_modules/@moduleName/subName/index.js

@Kompwu
Copy link
Contributor

Kompwu commented May 1, 2018

@jglover Hi, It' d be easier to help you if we had a chunk of code at least. 😉

@nchanged
Copy link
Contributor

FuseBox v4 Major Upgrade

As of today, the latest major version of FuseBox v4 is available in fuse-box@next. FuseBox has undergone a full re-write from scratch, learning from its mistakes in the previous versions.

There are a lot of improvements, speed and config wise.

Get started here

We are still working on the documentation and polishing before the major release. We are getting very close. And we need help testing.

npm install fuse-box@next

Most of the issues that I am closing have been resolved, however, if you find that your issue is still relevant in v4 don't hesitate to re-open or (better) create a new one with v4 configuration.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants