Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrated web component uses wrong base-href in Angular 6

I just created my first web-component using Angular 6. Everything worked fine, until I tried to integrate the web component into an existing application:

Application that integrates web component (https://www.example.com):

<script type="text/javascript" src="https://component.example.com/html-imports.min.js"></script>
<link rel="import" href="https://component.example.com/element.html">
<my-web-component uuid="2342-asdf-2342-ffsk"></my-web-component>

My web component index.html does not contain a base-href.

The browser now tries to load the assets of the web component:

https://www.example.com/assets/i18n/de_CH.json

instead

 https://component.example.com/assets/i18n/de_CH.json

When I try to add the base-href during the build, it results in this:

ng build --configuration=development --base-href https://component.example.com/

Cannot read property 'startTag' of null          
TypeError: Cannot read property 'startTag' of null
    at IndexHtmlWebpackPlugin.<anonymous> (/home/www-data/.../node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin.js:147:62)
    at Generator.next (<anonymous>)
    at fulfilled (/home/www-data/.../node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin.js:4:58)

Any help is really appreciated, I am running out of ideas.

like image 900
nimrod Avatar asked Jul 06 '18 19:07

nimrod


1 Answers

A few tips first:

  • As Skorunka suggests, you should structure the <base> already in the <head> since all of them share the same starting URL. Also, it does not make sense to use both relative and absolute URLs in this case.
  • The --base-href configuration can even override the one in HTML so don't worry.
  • Detele the type in script tag, it's definitely not Javascript and it's not necessary.
  • Final look:

    <base href="https://component.example.com/">
    <script src="html-imports.min.js"></script>
    <link rel="import" href="element.html">
    <my-web-component uuid="2342-asdf-2342-ffsk"></my-web-component>
    

Back to the problem, can you give me a fiddle of your component source code? The problem may lie within the way you load files inside the component, not the way you import the component, nor the code in here.

like image 87
Binh Bui Avatar answered Sep 30 '22 18:09

Binh Bui