解决VUE项目在IIS部署出现:Uncaught SyntaxError: Unexpected token < 报错
作者:農碼一生
这篇文章介绍了解决VUE项目在IIS部署出现:Uncaught SyntaxError: Unexpected token < 报错的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
一、第一个解决方法是把mode改成history这个问题就会消失
二、第二个解决方法是publicPath设置成’/’,不能是’./’
const publicPath='';
module.exports = {
// publicPath: process.env.NODE_ENV === 'production' ? '/lucky-draw' : '/'
publicPath: `/${publicPath}`
};三、报错404 Not Found,请重写url
在IIS正常部署完vue项目上之后,需要对URL重定向,原因是vue是根据vue-router转发路由访问url,在这里我们应该进行url rewrite。url write的方式有两种
1、在iis下载url rewrite工具配置规则
下载所需模块:urlrewrite

2、配置web.config文件
最终我使用了该方式,简单方便,和使用URL重写原理是一样的
web.config的内容:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".ttf" mimeType="font/x-ttf" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="text/json" />
</staticContent>
<rewrite>
<rules>
<rule name="vue" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>将该文件拷贝到打包好根目录下面

到此这篇关于解决VUE项目在IIS部署出现:Uncaught SyntaxError: Unexpected token < 报错的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 解决vite项目Uncaught Syntaxerror:Unexpected token>vue项目上线白屏问题
- VUE3刷新页面报错问题解决:Uncaught SyntaxError:Unexpected token '<'
- Vue项目报错:Uncaught SyntaxError: Unexpected token '<'的解决方法
- Vue项目报错:Uncaught SyntaxError: Unexpected token <
- vue-cli 打包后提交到线上出现 "Uncaught SyntaxError:Unexpected token" 报错
- vue出现Uncaught SyntaxError:Unexpected token问题及解决
