Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate production build with sourcemaps in Angular - CLI

How to keep sourcemaps after production build?

Right now, my command looks like this:

"build-prod": "ng build --app=release -prod && cp -R lang dist"

I tried changing it to:

ng build --app=release --sourceMap=true -prod && cp -R lang dist

but nothing changed.

If I do: ng build --sourcemap I get sourcemaps but then I get index.html instead of index.prod.html.

Is it possible to edit the first command to build sourcemap files?

this is my tsconfig.json file:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ]
    }
}
like image 739
user122222 Avatar asked Aug 26 '19 15:08

user122222


People also ask

Which command is used to build application in production mode in Angular?

To build your application for production, use the build command. By default, this command uses the production build configuration. This command creates a dist folder in the application root directory with all the files that a hosting service needs for serving your application.

What is Sourcemaps in Angular?

The source map explorer determines which file each byte in your minified code came from. It shows you an interactive tree-map visualization to help you debug where all the code is coming from. Before starting I would like to recommend this video from Stephen Fluin, angular team member.


2 Answers

You should edit your angular.json like this

"configurations": {
    "production": {
        "fileReplacements": [
            {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
            }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false, // change to true

Then run

ng build --prod

But I wouldnt recommend you turn on source map in production because it will increase a bundle size

like image 196
Tony Ngo Avatar answered Oct 16 '22 08:10

Tony Ngo


you can try

ng build --prod --source-map=true|false

angular.io/cli/build

like image 29
Muhammed Moussa Avatar answered Oct 16 '22 06:10

Muhammed Moussa