123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- 'use strict';
- var stripAnsi = require('strip-ansi');
- var url = require('url');
- var launchEditorEndpoint = require('./launchEditorEndpoint');
- var formatWebpackMessages = require('./formatWebpackMessages');
- var ErrorOverlay = require('react-error-overlay');
- ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) {
-
- fetch(
- launchEditorEndpoint +
- '?fileName=' +
- window.encodeURIComponent(errorLocation.fileName) +
- '&lineNumber=' +
- window.encodeURIComponent(errorLocation.lineNumber || 1) +
- '&colNumber=' +
- window.encodeURIComponent(errorLocation.colNumber || 1)
- );
- });
- var hadRuntimeError = false;
- ErrorOverlay.startReportingRuntimeErrors({
- onError: function () {
- hadRuntimeError = true;
- },
- filename: '/static/js/bundle.js',
- });
- if (module.hot && typeof module.hot.dispose === 'function') {
- module.hot.dispose(function () {
-
- ErrorOverlay.stopReportingRuntimeErrors();
- });
- }
- var connection = new WebSocket(
- url.format({
- protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
- hostname: process.env.WDS_SOCKET_HOST || window.location.hostname,
- port: process.env.WDS_SOCKET_PORT || window.location.port,
-
- pathname: process.env.WDS_SOCKET_PATH || '/sockjs-node',
- slashes: true,
- })
- );
- connection.onclose = function () {
- if (typeof console !== 'undefined' && typeof console.info === 'function') {
- console.info(
- 'The development server has disconnected.\nRefresh the page if necessary.'
- );
- }
- };
- var isFirstCompilation = true;
- var mostRecentCompilationHash = null;
- var hasCompileErrors = false;
- function clearOutdatedErrors() {
-
- if (typeof console !== 'undefined' && typeof console.clear === 'function') {
- if (hasCompileErrors) {
- console.clear();
- }
- }
- }
- function handleSuccess() {
- clearOutdatedErrors();
- var isHotUpdate = !isFirstCompilation;
- isFirstCompilation = false;
- hasCompileErrors = false;
-
- if (isHotUpdate) {
- tryApplyUpdates(function onHotUpdateSuccess() {
-
-
- tryDismissErrorOverlay();
- });
- }
- }
- function handleWarnings(warnings) {
- clearOutdatedErrors();
- var isHotUpdate = !isFirstCompilation;
- isFirstCompilation = false;
- hasCompileErrors = false;
- function printWarnings() {
-
- var formatted = formatWebpackMessages({
- warnings: warnings,
- errors: [],
- });
- if (typeof console !== 'undefined' && typeof console.warn === 'function') {
- for (var i = 0; i < formatted.warnings.length; i++) {
- if (i === 5) {
- console.warn(
- 'There were more warnings in other files.\n' +
- 'You can find a complete log in the terminal.'
- );
- break;
- }
- console.warn(stripAnsi(formatted.warnings[i]));
- }
- }
- }
- printWarnings();
-
- if (isHotUpdate) {
- tryApplyUpdates(function onSuccessfulHotUpdate() {
-
-
- tryDismissErrorOverlay();
- });
- }
- }
- function handleErrors(errors) {
- clearOutdatedErrors();
- isFirstCompilation = false;
- hasCompileErrors = true;
-
- var formatted = formatWebpackMessages({
- errors: errors,
- warnings: [],
- });
-
- ErrorOverlay.reportBuildError(formatted.errors[0]);
-
- if (typeof console !== 'undefined' && typeof console.error === 'function') {
- for (var i = 0; i < formatted.errors.length; i++) {
- console.error(stripAnsi(formatted.errors[i]));
- }
- }
-
-
- }
- function tryDismissErrorOverlay() {
- if (!hasCompileErrors) {
- ErrorOverlay.dismissBuildError();
- }
- }
- function handleAvailableHash(hash) {
-
- mostRecentCompilationHash = hash;
- }
- connection.onmessage = function (e) {
- var message = JSON.parse(e.data);
- switch (message.type) {
- case 'hash':
- handleAvailableHash(message.data);
- break;
- case 'still-ok':
- case 'ok':
- handleSuccess();
- break;
- case 'content-changed':
-
- window.location.reload();
- break;
- case 'warnings':
- handleWarnings(message.data);
- break;
- case 'errors':
- handleErrors(message.data);
- break;
- default:
-
- }
- };
- function isUpdateAvailable() {
-
-
-
- return mostRecentCompilationHash !== __webpack_hash__;
- }
- function canApplyUpdates() {
- return module.hot.status() === 'idle';
- }
- function tryApplyUpdates(onHotUpdateSuccess) {
- if (!module.hot) {
-
- window.location.reload();
- return;
- }
- if (!isUpdateAvailable() || !canApplyUpdates()) {
- return;
- }
- function handleApplyUpdates(err, updatedModules) {
-
- const hasReactRefresh = process.env.FAST_REFRESH;
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
-
- if (!hasReactRefresh && wantsForcedReload) {
- window.location.reload();
- return;
- }
- if (typeof onHotUpdateSuccess === 'function') {
-
- onHotUpdateSuccess();
- }
- if (isUpdateAvailable()) {
-
- tryApplyUpdates();
- }
- }
-
- var result = module.hot.check( true, handleApplyUpdates);
-
- if (result && result.then) {
- result.then(
- function (updatedModules) {
- handleApplyUpdates(null, updatedModules);
- },
- function (err) {
- handleApplyUpdates(err, null);
- }
- );
- }
- }
|