简体   繁体   中英

How to load a local html file into a NativeScript webview

I have modified the webpack.config.js to add a local file called index.html the code below :

new CopyWebpackPlugin([
    { from: { glob: "index.html" } },
    { from: { glob: "fonts/**" } },
    { from: { glob: "**/*.jpg" } },
    { from: { glob: "**/*.png" } },
 ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),

This is how I configured my webview in the main-page.xml file the code below:

<WebView row="1" loaded="onWebViewLoaded" id="myWebView" src="index.html"/>

In NativeScript, by default, the tilde ( ~ ) marks the app root folder (note the App and not the Project!). So if your file is located in <project-name>/app/index.html try setting the path with ~/index.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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