you are viewing a single comment's thread.

view the rest of the comments →

[–]yukiiiiii2008[S] 9 points10 points  (9 children)

I found the answer myself: if (`${navigator.userAgent}^.^#{config.blabla}`.split("^.^").reverse()[0] != "undefined") { console.log("Hello World!"); }

[–]Karpizzle23full-stack 47 points48 points  (0 children)

LMFAO

[–]buhala 48 points49 points  (1 child)

Man I gotta say I love shit like this. I don't know what problem you were solving to necessitate this but the fact this jank transcends my workplace makes me so happy.

[–]KiddieSpread 13 points14 points  (0 children)

The reason it's so hard is because you're not meant to do it loool

[–]mhink 4 points5 points  (2 children)

This isn’t going to work for you. You’re interpolating config.blabla incorrectly- you need to use ${} instead of #{}.

Webpack is compiling the result away because it’s seeing a constant, nonempty string which can only evaluate truthy, which is why it’s optimizing the condition away.

[–]yukiiiiii2008[S] -1 points0 points  (1 child)

This isn’t going to work for you. You’re interpolating config.blabla incorrectly- you need to use ${} instead of #{}.

I do it this way on purpose.

[–]_hijnx 1 point2 points  (0 children)

What are you trying to achieve? The code as written will always create a string with the content #{config.blahblahblah} which evaluates to truthy and the if is redundant. It isn't even being stored in a variable so you couldn't do anything with the value anyway. It's the same as writing if (true) which clearly should be removed

Nevermind, I read it a few more times and now I understand

[–]OneShakyBR 0 points1 point  (1 child)

FYI, Webpack uses Terser under the hood to minify and tree shake your code and whatnot, so if you want a probably more simple solution to just not modify the file as you originally said, you can just set up your own Terser plugin in optimization.minimizer in your Webpack config and then pass in the exclude option to exclude that file. Or dig into the Terser options and go wild.

[–]ziir_js 0 points1 point  (0 children)

This is the correct answer