I am developing an app with Typescript, Angular2 and Ionic2. Now when I am running the file in de browser, I can see all the source code from the .ts files..
Does anybody knows how to hide this? See image below.
To hide/show an element in TypeScript, use the style.display property to determine if the element is shown or hidden. If its display property is set to none, show the element by setting it to block, otherwise hide the element by setting its display property to none. Here is the HTML for the examples in this article.
When your app is running in a browser like Firefox, the browser is running JavaScript. Even though the browser is running that JavaScript, if you open the debugger in Firefox, the debugger will display the TypeScript source code and will let you set break points in it.
TypeScript can easily be used programmatically for files on the file system. With a little configuration it can even be run on code that only exists in memory. However, running TypeScript in the browser with no access to the file system turned out to be a bit more challenging than I thought.
function typecheck (code: string): TypeError [] { /* ... */ } For this I reached for the TypeScript language service, which is a layer on top of the core compiler and provides common editor like operations. A ts.System contains methods for reading files, writing files, checking if a file exists, etc.
In your tsconfig.json
file:
"compilerOptions": {
...
"sourceMap": false,
...
}
If you disable source maps, your typescript will no longer be loaded from the map files. But to completly "hide" them, you can remove them once you push your code in production, since typescript is absolutly not needed for your application to work once it's transpilled to JS.
Also, keep in mind that Typescript is transpilled to JS which is still client-side code, and it will be readable by the client. If you want to obfuscate your code, you should take a look at webpack (which is used by angular-cli)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With