Comments (6)
This works, but it is as ugly as it sounds.
from systemjs.
I was exploring new System.constructor()
, but that does not help me as it appears to be a full clone of the parent SystemJS (with configuration) instead of being a fresh unconfigured instance that I could then call mySystem.import(entry_url)
and have reasonable assurance that it would work since that is how we are using our SJS.
from systemjs.
Although hacky and unsupported, you can make your own custom build of systemjs. The main thing of interest is that SystemJS installs itself to envGlobal
https://github.com/systemjs/systemjs/blob/main/dist/s.js (line 14 and 504) which is defined as the unqualified variable self
if present.
var envGlobal = hasSelf ? self : global;
.
.
.
envGlobal.System = new SystemJS();
So in an IIFE you can define your own self
variable and SystemJS will install itself into that.
(function() {
var self = {};
// copy s.js to here
window.MySystemJS = self;
})();
Now you can call MySystemJS.System.import(...)
and be completely isolated
from systemjs.
Now you can call
MySystemJS.System.import(...)
and be completely isolated
As far as I can tell, I would need to also modify my bundles (created by Rollup using format: system
) to refer to MySystemJS.System.register
. Am I correct about that, or will the System.register
that the downloaded bundles see be scoped to MySystemJS.System
?
from systemjs.
As far as I can tell, I would need to also modify my bundles (created by Rollup using
format: system
) to refer toMySystemJS.System.register
. Am I correct about that, or will theSystem.register
that the downloaded bundles see be scoped toMySystemJS.System
?
Yes, unfortunately you are right about that (most of my modules are globals, so I wasn't thinking of System.register()
). Some (not very good choices) I can think of:
-
As you suggested, change all your
System.register
toMySystemJS.System.register
in your modules (could probably be ased
script you run on your output). -
If you only have to worry about
System
being defined, but notamd
methods (define
), instruct rollup to produceamd
modules and use the amd compatibility mode of SystemJS. You'd also need to copy thedefine
method fromMySystemJS
towindow
at the bottom of the code above. Semantics of amd are a bit different than SystemJS, so may or may not work depending on how complex your imports are. -
If it's safe to target only browsers implementing
fetch
, you can put SystemJS in its fetch-eval mode (override the shouldFetch method to always return true). Then you make a customeval
(which your version of System would use) where you swap with the global System and then eval:
(function() {
var self = {};
// note: redefining eval like this is not supported in strict mode, but will work in a `loose` function
var eval = function(code) {
var backupSystem = window.System;
try{
window.System = self.System;
window.eval(code); // indirect call of eval -- will always execute in the global scope and is much safer
} finally {
window.System = backupSystem;
}
};
// copy s.js to here
self.System.constructor.prototype.shouldFetch = function () { return true; };
window.MySystemJS = self; // or maybe `window.MySystemJS = self.System` to be a little simpler
})();
Can add a fetch polyfill too if needed. Loaded scripts need to be samesite or CORS enabled.
from systemjs.
Thank you. You can assume that I have a rant that I don’t want to have to think about any of this stuff, just be able to deploy and have it work without conflicts. It doesn't help that the client is on an ancient version of SystemJS that does not work like modern versions of SystemJS at all, so I think that I was always going to end up having to do something … "unsafe" like this.
I'll see if I can do some text-replace magic in the bundles &c. to see if the concept will work and try from there.
from systemjs.
Related Issues (20)
- [NodeJS] Should System.import('my-module') refetch if called twice? HOT 2
- Multiple dependencies bundled in one file (previously "bundles" config option)
- Distribution Files published to npm do not match what is in GitHub for version 16.14.2 (have windows style line breaks)
- Definitelytyped types for system-node.cjs HOT 1
- Top-level await does not wait for its dependencies HOT 1
- system.min.js doesn't include latest version HOT 1
- Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection') HOT 1
- Support fetchPriority with external import maps HOT 1
- Content Security Policy `unsafe-eval` and `unsafe-inline` still required? HOT 1
- I need to prevent SystemJS attempting to load dependencies on Shopify site, urls require a version parameter that SystemJS doesn't know HOT 1
- importMap dependencies error
- Should consumers be aware of `process.env.SYSTEM_PRODUCTION` HOT 1
- Logging for SystemJS Error#3
- Wrong module content when importing latest react-router-dom versions HOT 2
- Conflict with other amd module imports HOT 2
- transform extra skips doesn't use `this.fetch` HOT 1
- Auto import dependencies HOT 4
- difference in phone HOT 1
- Please help analyze how this problem arises. HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from systemjs.