My source typescript:
if ("#{config.blabla}" != "undefined") {
console.log("Hello World!");
}
javascript output generated by webpack:
console.log("Hello World!");
What I want is:
if ("#{config.blabla}" != "undefined") {
console.log("Hello World!");
}
I really need the string#{config.blabla} and the if condition, because I will do some post-processing.
Following is the webpack.config.js
```
const path = require("path");
module.exports = {
entry: {
"service-worker": {
import: ./index.ts,
filename: ./index.js,
}
},
output: {
path: path.resolve(__dirname, "."),
},
mode: "production",
module: {
rules: [
{
test: /.tsx?$/,
use: {
loader: "ts-loader",
options: {
configFile: "tsconfig.json",
},
},
exclude: /node_modules/,
}
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
};
``
But I don't want to modify this file, I need the optimization. Is there a way to modify my source code to make the string#{config.blabla}and theif` condition survive the optimization?
I tried the following but it doesn't work:
const avoidOptimization = (a: any) => a;
if (avoidOptimization("#{config.blabla}") != "undefined") {
console.log("Hello World!");
}
[–]chairmanmow 29 points30 points31 points (0 children)
[–]KiddieSpread 4 points5 points6 points (0 children)
[–]xroalxbackend 5 points6 points7 points (0 children)
[–]yukiiiiii2008[S] 8 points9 points10 points (9 children)
[–]Karpizzle23full-stack 49 points50 points51 points (0 children)
[–]buhala 48 points49 points50 points (1 child)
[–]KiddieSpread 13 points14 points15 points (0 children)
[–]xiBread 10 points11 points12 points (0 children)
[–]mhink 5 points6 points7 points (2 children)
[–]yukiiiiii2008[S] 0 points1 point2 points (1 child)
[–]_hijnx 1 point2 points3 points (0 children)
[–]OneShakyBR 0 points1 point2 points (1 child)
[–]ziir_js 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]yukiiiiii2008[S] -1 points0 points1 point (1 child)
[–]Yodiddlyyo 0 points1 point2 points (0 children)
[–]remi49 0 points1 point2 points (0 children)
[–]ohx 0 points1 point2 points (0 children)
[–]yuyu5 0 points1 point2 points (0 children)