简体   繁体   English

如何调试角度元素?

[英]How to debug angular-elements?

I built a project using angular-elements and managed to successfully embed a component into another application.我使用 angular-elements 构建了一个项目,并成功地将一个组件嵌入到另一个应用程序中。 What I would like to do now is be able to debug the original component from the application it is included in.我现在想做的是能够从包含它的应用程序中调试原始组件。

All the logic for the component is in one file, which is a concatenation of 4 files created by Angular during build - runtime.js, polyfills.js, scripts.js, main.js .组件的所有逻辑都在一个文件中,它是由 Angular 在构建期间创建的 4 个文件的串联 - runtime.js、polyfills.js、scripts.js、main.js

The js.map files for those 4 files are also created during build and I can successfully place & hit a breakpoint in the original main.ts file (after including the jsmaps in the directory with the output file for the element).这 4 个文件的js.map文件也是在构建过程中创建的,我可以成功地在原始main.ts文件中放置并命中一个断点(在包含元素输出文件的目录中包含 jsmap 之后)。 However, I have been unable to find a way to debug the actual component.ts file from the application that is using it.但是,我一直无法找到一种方法来从使用它的应用程序调试实际的component.ts文件。 The js.map for that component is also included in the bundle and I can view the component.ts file through Chrome DevTools, but if I put any breakpoints they will never be hit.该组件的js.map也包含在包中,我可以通过 Chrome DevTools 查看 component.ts 文件,但如果我放置任何断点,它们将永远不会被命中。

app.module.ts app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Injector } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { FormsModule } from "@angular/forms";

import { FirstWebElementComponent } from './first-web-element/first-web-element.component';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { ScenarioSelectorComponent } from './scenario-selector/scenario-selector.component';

@NgModule({
  declarations: [
    AppComponent,
    ScenarioSelectorComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,    
    HttpClientModule
  ],
  providers: [],    
  entryComponents: [ScenarioSelectorComponent]
})
export class AppModule {
  constructor(private injector: Injector) {}

  ngDoBootstrap() {    
    const scenarioSelector = createCustomElement(ScenarioSelectorComponent, {injector: this.injector});    
    customElements.define('scenario-selector', scenarioSelector);
  }
 }

main.ts主文件

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

To the best of my understanding, the component.ts file logic is included in main.js file during build, but there doesn't seem to be a map created describing the connection between the two.据我所知,component.ts 文件逻辑在构建期间包含在 main.js 文件中,但似乎没有创建描述两者之间连接的映射。

For reference, here is the stuff I read / watched.作为参考,这是我阅读/观看的内容。
Building Custom Elements / Web Components with Angular 6 使用 Angular 6 构建自定义元素/Web 组件
Angular Elements – A Practical Introduction To Web Components With Angular 6 Angular Elements – 使用 Angular 6 的 Web 组件实用介绍

Angular CLI doesn't support inline source maps anymore. Angular CLI 不再支持内联源映射。 Your best bet is to replace ng build with ngx build plus - https://github.com/manfredsteyer/ngx-build-plus你最好的选择是用ngx build plus替换ng build - https://github.com/manfredsteyer/ngx-build-plus

Then add a build plugin to replace the devtool with inline-source-map which will inline the sourcemaps into your bundle file enabling you to debug.然后添加一个构建插件,用inline-source-map替换devtool ,它将inline-source-map内联到您的包文件中,使您能够进行调试。

See: https://stackoverflow.com/a/54548171/1829251参见: https : //stackoverflow.com/a/54548171/1829251

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM