Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Typescript files in browser?

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.

enter image description here

like image 385
Royal Avatar asked Nov 07 '16 09:11

Royal


People also ask

How to hide/show an element in typescript?

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.

How do I debug TypeScript code in Firefox?

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.

Can typescript be used without a file system?

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.

What is the function of typecheck in typescript?

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.


1 Answers

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)

like image 145
Supamiu Avatar answered Oct 12 '22 13:10

Supamiu