Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CSS sourcemaps for Angular 6 application?

How do I enable sourcemaps for CSS files in my Angular 6 application?

I'm defining my styles source code in SCSS files, which are later compiled to CSS by Angular CLI. However, I can't see the original source code in the browser during styles debugging. All styles are pointing to the <style>...</style> blocks.

I want to be able to see the references to original SCSS files when debugging the compiled code.

What options do I need to set in angular.json file?


I've tried to use --source-map CLI argument for ng serve command, but it looks like it's not affecting anything. Sourcemap files are emitted in both cases according to webpack compilation log.

like image 204
Slava Fomin II Avatar asked May 13 '18 16:05

Slava Fomin II


Video Answer


1 Answers

From https://github.com/angular/angular-cli/issues/9099#issuecomment-388710635

1) modify angular.json to add --extract-css, in 6.0 this argument is removed from ng serve

 "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
       ---
      },
      "configurations": {
        "production": {
          ---
        },
        "serve": {
          "extractCss": true,
           ---
        }
      }
    },

2) Then change serve->options->browserTarget->project-name:build to project-name:build:serve

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "open": true,
        "browserTarget": "<project-name>:build:serve"
      },
      "configurations": {
        "production": {
          ---
        }
      }
    }

3) run ng serve --source-map

like image 109
Alex Spera Avatar answered Nov 13 '22 07:11

Alex Spera