Skip to content

Instantly share code, notes, and snippets.

@bennyng
Created September 14, 2019 07:31
Show Gist options
  • Save bennyng/bbce46a676df62f5d990cc0010d484ff to your computer and use it in GitHub Desktop.
Save bennyng/bbce46a676df62f5d990cc0010d484ff to your computer and use it in GitHub Desktop.
Flutter web main.dart.js
(function() {
var _currentDirectory = (function () {
var _url;
var lines = new Error().stack.split('\n');
function lookupUrl() {
if (lines.length > 2) {
var match = lines[1].match(/^\s+at (.+):\d+:\d+$/);
// Chrome.
if (match) return match[1];
// Chrome nested eval case.
match = lines[1].match(/^\s+at eval [(](.+):\d+:\d+[)]$/);
if (match) return match[1];
// Edge.
match = lines[1].match(/^\s+at.+\((.+):\d+:\d+\)$/);
if (match) return match[1];
// Firefox.
match = lines[0].match(/[<][@](.+):\d+:\d+$/)
if (match) return match[1];
}
// Safari.
return lines[0].match(/(.+):\d+:\d+$/)[1];
}
_url = lookupUrl();
var lastSlash = _url.lastIndexOf('/');
if (lastSlash == -1) return _url;
var currentDirectory = _url.substring(0, lastSlash + 1);
return currentDirectory;
})();
var baseUrl = (function () {
// Attempt to detect --precompiled mode for tests, and set the base url
// appropriately, otherwise set it to '/'.
var pathParts = location.pathname.split("/");
if (pathParts[0] == "") {
pathParts.shift();
}
if (pathParts.length > 1 && pathParts[1] == "test") {
return "/" + pathParts.slice(0, 2).join("/") + "/";
}
// Attempt to detect base url using <base href> html tag
// base href should start and end with "/"
if (typeof document !== 'undefined') {
var el = document.getElementsByTagName('base');
if (el && el[0] && el[0].getAttribute("href") && el[0].getAttribute
("href").startsWith("/") && el[0].getAttribute("href").endsWith("/")){
return el[0].getAttribute("href");
}
}
// return default value
return "/";
}());
var mapperUri = baseUrl + "packages/build_web_compilers/src/" +
"dev_compiler_stack_trace/stack_trace_mapper.dart.js";
var requireUri = baseUrl +
"packages/build_web_compilers/src/dev_compiler/require.js";
var mainUri = _currentDirectory + "main_web_entrypoint.dart.bootstrap";
if (typeof document != 'undefined') {
var el = document.createElement("script");
el.defer = true;
el.async = false;
el.src = mapperUri;
document.head.appendChild(el);
el = document.createElement("script");
el.defer = true;
el.async = false;
el.src = requireUri;
el.setAttribute("data-main", mainUri);
document.head.appendChild(el);
} else {
importScripts(mapperUri, requireUri);
require.config({
baseUrl: baseUrl,
});
// TODO: update bootstrap code to take argument - dart-lang/build#1115
window = self;
require([mainUri + '.js']);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment