Search code examples
androidwebviewnativescript

Nativescript App - load local HTML/JS/CSS in Webview


If I want to display a local html file in a Webview, how can I do it?

Tried Solutions:

this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/monitordaten/webview/assets/graph.html`); 
<Webview #myWebView [src]="htmlPath" ></Webview>
new CopyWebpackPlugin([
               { from: { glob: "monitrodaten/webview/assets/**"} },          <= Added this row
               { from: { glob: "fonts/**" } },
               { from: { glob: "**/*.jpg" } },
               ...

both solutions lead to the following error: enter image description here Filestructure:
enter image description here


Solution

  • Your path lacks of "app"

    this.htmlPath = encodeURI(`${fs.knownFolders.currentApp().path}/app/monitordaten/webview/assets/graph.html`); 
    

    or

    this.htmlPath = encodeURI(`~/app/monitordaten/webview/assets/graph.html`);
    

    webpack config

    { from: { glob: "app/monitrodaten/webview/assets/**"} }