Detect node system better
Some things like webpack create the “global” variable so we cannot
rely on just that to detect nodejs systems. To supplement this, we can
also check for the “require” function. This fixes an issue where
require is undefined when using jsaddle-warp.
commit99514aff98655257677068dc60dae514bb7ac01c
authorMatthew Bauer <mjbauer95@gmail.com>
dateFri 8 Nov 2019, 11:47 (7 years ago)
parent471b442
jsaddle-warp/src/Language/Javascript/JSaddle/WebSockets.hs+1−1
@@ -164,7 +164,7 @@ jsaddleJs = jsaddleJs' Nothing
164164-- sed -e 's|\\|\\\\|g' -e 's|^| \\|' -e 's|$|\\n\\|' -e 's|"|\\"|g' data/jsaddle.js | pbcopy
165165jsaddleJs' :: Maybe ByteString -> Bool -> ByteString
166166jsaddleJs' jsaddleUri refreshOnLoad = "\
167− \if(typeof global !== \"undefined\") {\n\
167+ \if(typeof global !== \"undefined\" && typeof require == \"function\") {\n\
168168 \ global.window = global;\n\
169169 \ global.WebSocket = require('ws');\n\
170170 \}\n\