Skip to content

Commit 1694b52

Browse files
fix: speed up initial client bundling
1 parent 3ed754d commit 1694b52

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

client-src/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* global __resourceQuery, __webpack_hash__ */
22
/// <reference types="webpack/module" />
33
import webpackHotLog from "webpack/hot/log.js";
4-
import stripAnsi from "./utils/stripAnsi.js";
54
import parseURL from "./utils/parseURL.js";
65
import socket from "./socket.js";
76
import { formatProblem, createOverlay } from "./overlay.js";
@@ -165,6 +164,31 @@ const overlay =
165164
)
166165
: { send: () => {} };
167166

167+
const ansiRegex = new RegExp(
168+
[
169+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
170+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
171+
].join("|"),
172+
"g",
173+
);
174+
175+
/**
176+
*
177+
* Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
178+
* Adapted from code originally released by Sindre Sorhus
179+
* Licensed the MIT License
180+
*
181+
* @param {string} string
182+
* @return {string}
183+
*/
184+
const stripAnsi = (string) => {
185+
if (typeof string !== "string") {
186+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
187+
}
188+
189+
return string.replace(ansiRegex, "");
190+
};
191+
168192
const onSocketMessage = {
169193
hot() {
170194
if (parsedResourceQuery.hot === "false") {

client-src/utils/stripAnsi.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)