详解vue-cli 构建Vue项目遇到的坑

前端之家收集整理的这篇文章主要介绍了详解vue-cli 构建Vue项目遇到的坑前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

使用Vue做管理系统和WebApp做过三四个项目了,期间遇到很多坑,再次一一列举,并给出解决方案,方便日后更方便使用,也为他人提供一些解决方案。

问题表象和解决方

1、编译后js、css等相对路径和绝对路径

文件 build: { env: require('./prod.env'),index: path.resolve(__dirname,'../dist/index.html'),assetsRoot: path.resolve(__dirname,'../dist'),assetsSubDirectory: 'static',assetsPublicPath: './',// "./"表示相对路径 编译结果 productionSourceMap: true,// Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`,make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false,productionGzipExtensions: ['js','css'],// Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report },

2、CSS中图片相对路径编译后,路径不对。

解决方案 修改build/untils.js //替换相应代码 if (options.extract) { return ExtractTextPlugin.extract({ use: loaders,publicPath: '../../',//注意: 此处根据路径,自动更改 ,(imgurl='static/img/*.jpg') fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) }

3、使用代理,解决跨域请求。

vue-cli已经集成 http-proxy-middleware插件

github:https://github.com/chimurai/http-proxy-middleware

其中 target的值一定不可以包含工程名,否则可能会出现服务器Session问题

4、用Vue做页面,利用phonegap编译android APP时,兼容问题。

cordova android 4.0 以下的默认webView,不支持ES6,会导致一些列问题。

好在,cordova android允许我们自定义自己的webView引擎。那么我们就想到了 腾讯浏览服务X5内核。

然而有大神基于此内核编写了cordova 插件

githup:https://github.com/offbye/cordova-plugin-x5engine-webview

使用此插件很好的解决 低版本安卓不支持Vue。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

原文链接:https://www.f2er.com/vue/36749.html

猜你在找的Vue相关文章