Skip to content

Commit ffa472b

Browse files
committed
fix: prod build doesnt inject live preview styles are replace comments stripped by build
1 parent d2d332f commit ffa472b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

gulpfile.js/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ function makeJSDist() {
9999
mangle: false,
100100
compress: {
101101
unused: false
102+
},
103+
preserveComments: function (node, comment) {
104+
const text = (comment.value || "").trim();
105+
106+
// Preserve ONLY comments starting with "DONT_STRIP_MINIFY:"
107+
return text.includes("DONT_STRIP_MINIFY:");
102108
}
103109
}))
104110
.pipe(sourcemaps.write('./'))
@@ -555,9 +561,7 @@ function inlineTextRequire(file, content, srcDir) {
555561
textContentMap[requirePath] = fileContent;
556562
textContent = fileContent;
557563
}
558-
if(textContent.includes("`")) {
559-
console.log("Not inlining file as it contains a backquote(`) :", requirePath);
560-
} else if(requirePath.endsWith(".js") || requirePath.endsWith(".json")) {
564+
if(requirePath.endsWith(".js") || requirePath.endsWith(".json")) {
561565
console.log("Not inlining JS/JSON file:", requirePath);
562566
} else {
563567
console.log("Inlining", requireStatement);
@@ -568,7 +572,7 @@ function inlineTextRequire(file, content, srcDir) {
568572
throw `Error inlining ${requireStatement} in ${file}: Regex: ${detectedRegEx}`+
569573
"\nRegular expression of the form /*/ is not allowed for minification please use RegEx constructor";
570574
}
571-
content = content.replaceAll(requireStatement, "`"+textContent+"`");
575+
content = content.replaceAll(requireStatement, `${JSON.stringify(textContent)}`);
572576
}
573577
}
574578

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function RemoteFunctions(config = {}) {
103103

104104
let strings = {}, icons = {}, cssStyles = {}; // these will be injected below
105105
// the below code comment is replaced by added scripts for extensibility
106-
// REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS
106+
// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS
107107

108108
/**
109109
* this function is responsible to auto scroll the live preview when
@@ -5298,7 +5298,7 @@ function RemoteFunctions(config = {}) {
52985298

52995299
let customReturns = {};
53005300
// the below code comment is replaced by added scripts for extensibility
5301-
// REPLACE_WITH_ADDED_REMOTE_SCRIPTS
5301+
// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_SCRIPTS
53025302

53035303
return {
53045304
...customReturns,

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ define(function (require, exports, module) {
343343
const remoteScriptText = Array.from(remoteFunctionsScripts.values()).join("\n");
344344
const remoteConstantScriptText = Array.from(remoteFunctionsConstantsScripts.values()).join("\n");
345345
effectiveRemoteFunctionsScripts = RemoteFunctions
346-
.replace("// REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS", remoteConstantScriptText)
347-
.replace("// REPLACE_WITH_ADDED_REMOTE_SCRIPTS", remoteScriptText);
346+
.replace("// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS", remoteConstantScriptText)
347+
.replace("// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_SCRIPTS", remoteScriptText);
348348
}
349349

350350
function addRemoteFunctionScript(scriptName, scriptText) {
@@ -353,7 +353,7 @@ define(function (require, exports, module) {
353353
return false;
354354
}
355355
remoteFunctionsScripts.set(scriptName, scriptText);
356-
if(!RemoteFunctions.includes("// REPLACE_WITH_ADDED_REMOTE_SCRIPTS")){
356+
if(!RemoteFunctions.includes("// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_SCRIPTS")){
357357
throw new Error("RemoteFunctions script is missing the placeholder // REPLACE_WITH_ADDED_REMOTE_SCRIPTS");
358358
}
359359
_computeRemoteScript();
@@ -366,7 +366,7 @@ define(function (require, exports, module) {
366366
return false;
367367
}
368368
remoteFunctionsConstantsScripts.set(scriptName, scriptText);
369-
if(!RemoteFunctions.includes("// REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS")){
369+
if(!RemoteFunctions.includes("// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS")){
370370
throw new Error("RemoteFunctions script missing placeholder // REPLACE_WITH_ADDED_REMOTE_CONSTANT_SCRIPTS");
371371
}
372372
_computeRemoteScript();

0 commit comments

Comments
 (0)