JSFiddle - React, Tailwind, and code Playground

by gianlucaguarini

HTML

<script>
const globals = {
	config: {
		staticFileManifest: {
  		'mamma.js': 'mia.js'
  	}
	}
};

</script>

JavaScript

(function() {
    /** !Don't try this at home! **/
    /**
     * Monkey patch the HTMLScriptElement prototype to change the webpack dynamic import path in runtime.
     * TODO: Pull request on webpack to standardize this instead!
     * @type {Object}
     */
    var src = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
    Object.defineProperty(HTMLScriptElement.prototype, 'src', {
        set(val) {
            var staticFileManifest = globals && globals.config && globals.config.staticFileManifest ? globals.config.staticFileManifest : { };
            val = staticFileManifest.hasOwnProperty(val) ? staticFileManifest[val] : val;
            return src.set.call(this, val);
        },
    });
}());

const s1 = document.createElement('script')
s1.src = 'mamma.js'
console.log(s1.src)
const s2 = document.createElement('script')
s2.src = 'papa.js'
console.log(s2.src)