1. Modify the configuration file of the vue project
- Change the value in
config
the folder toindex.js
assetsPublicPath
“./”
-
Webpack.prod.conf.js
output
Add parameters inpublicPath:'./'
-
in
webpack.base.conf.js
_
publicPath: process.env.NODE_ENV === '生产' ?'./' +config.build.assetsPublicPath : './' + config.dev.assetsPublicPath
2. Package the vue project
-
run
npm run build
-
Find the dist file in the project directory, this is the packaged file
3. Add in the Xcode project
-
Add files to project
-
Load the H5 page
/// 加载H5
private func loadH5() {
urlString = "dist/index.html"
guard let urlString = urlString else {
return
}
let url: URL?
if urlString.hasPrefix("http") {
url = URL(string: urlString)
} else {
url = Bundle.main.url(forResource: urlString, withExtension: nil)
}
guard let url = url else {
return
}
let request = URLRequest(url: url)
self.webView.load(request)
}