Skip to content

Commit

Permalink
✨ Add Blast.isServer support to minification
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 4, 2024
1 parent 0d33b37 commit c404ea0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/core/client_alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,20 @@ Alchemy.setMethod(function getAllCustomHandlers(type) {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.4.0
* @version 1.1.0
* @version 1.4.0
*
* @param {number} level
* @param {Array} args
* @param {Object} options
*/
Alchemy.setMethod(function printLog(level, args, options) {

var type,
line;

if (alchemy.settings.debugging.silent) {
if (Blast.isServer && this.settings.debugging.silent) {
return;
}

let type;

if (!Array.isArray(args)) {
args = [args];
}
Expand Down
5 changes: 4 additions & 1 deletion lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Alchemy.setMethod(function sourcemapMiddleware(req, res, nextMiddleware) {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.3.17
* @version 1.4.0
*
* @param {string} path
* @param {Object} options
Expand Down Expand Up @@ -419,6 +419,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
if (should_minify && typeof Terser?.minify == 'function') {

// Force Blast.isNode & Blast.isBrowser to be replaced later
data = data.replaceAll('Blast.isServer', '__BLAST_IS_SERVER');
data = data.replaceAll('Blast.isNode', '__BLAST_IS_NODE');
data = data.replaceAll('Blast.isBrowser', '__BLAST_IS_BROWSER');

Expand Down Expand Up @@ -448,6 +449,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
// Provide it some info on global definitions
global_defs : {
'__BLAST_IS_NODE' : false,
'__BLAST_IS_SERVER' : false,
'__BLAST_IS_BROWSER' : true
}
},
Expand Down Expand Up @@ -485,6 +487,7 @@ Alchemy.setMethod(function minifyScript(path, options, callback) {
if (result.code.indexOf('__BLAST_IS_') > -1) {
// Restore some instances in case these weren't removed by Terser
// (Maybe because they're part of another variable or a string)
result = result.code.replaceAll('__BLAST_IS_SERVER', 'Blast.isServer');
result = result.code.replaceAll('__BLAST_IS_NODE', 'Blast.isNode');
result = result.replaceAll('__BLAST_IS_BROWSER', 'Blast.isBrowser');
} else {
Expand Down

0 comments on commit c404ea0

Please sign in to comment.