The vue project is packaged and configured into the iOS project

1. Modify the configuration file of the vue project

  1. Change the value in configthe folder toindex.jsassetsPublicPath“./”

insert image description here

  1. Webpack.prod.conf.jsoutputAdd parameters inpublicPath:'./'
    insert image description here

  2. in webpack.base.conf.js_
    publicPath: process.env.NODE_ENV === '生产' ?'./' +config.build.assetsPublicPath : './' + config.dev.assetsPublicPath
    insert image description here

2. Package the vue project

  1. runnpm run build

  2. Find the dist file in the project directory, this is the packaged file

3. Add in the Xcode project

  1. Add files to project
    insert image description here

  2. 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)
    }

Guess you like

Origin blog.csdn.net/guoxulieying/article/details/131561014