npm安装anywhere( 随启随用的静态文件服务器),分分钟解决浏览器请求本地js文件跨域问题

以下是一个html文件, chrome浏览器打开该文件;

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=600, initial-scale=1.0">
    <title>Vite App</title>
    <script type="module" crossorigin src="/assets/index-GxicIufr.js"></script>
    <link rel="stylesheet" crossorigin href="/assets/index-U9LxSyeS.css">
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

报错如下:

js 复制代码
Access to script at 'file:///Users/***/Documents/code/learning/vue/vue-project/dist/assets/index-GxicIufr.js' 
from origin 'null' has been blocked by CORS policy: 
Cross origin requests are only supported for protocol schemes: 
http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html:8 
 Access to CSS stylesheet at 'file:///Users/shuangguiyu/Documents/code/learning/vue/vue-project/dist/assets/index-U9LxSyeS.css' 
 from origin 'null' has been blocked by CORS policy:
 Cross origin requests are only supported for protocol schemes:
 http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html
        

全局安装anywhere npm install -g anywhere,再前往html文件所在目录执行anywhere -p 8081

Anywhere 随启随用的静态文件服务器。 www.npmjs.com/package/any...

相关推荐
JustHappy15 分钟前
古法编程秘籍(七):互联网到底是什么?把两台电脑怎么说话搞懂就够了
前端·后端·网络协议
snow@li18 分钟前
SEO-文章标题:写文章时候,分类+主标题+大纲+解释 作为标题 / 不点进去也知道全文覆盖什么 / 标题即架构
前端
kyriewen1 小时前
Git Commit 前自动修复代码风格?配置 Husky + lint-staged,从此 CR 只聊逻辑
前端·git·面试
小和尚同志1 小时前
AI 自动化测试探索(一):Playwright MCP
前端·人工智能·aigc
老马识途2.02 小时前
在AI的帮助下理解spring的启动过程
java·前端·spring
徐小夕2 小时前
Loop Engineering 深度解析与实战指南(全网最全)
前端·算法·github
运筹vivo@3 小时前
Python ContextVar 底层机制与内存模型拆解
前端·数据库·python
#麻辣小龙虾#4 小时前
基于vue3.0开发一款【固废与废气运维管理系统】(支持源码)
前端·vue.js·vue3
Cosolar4 小时前
Docsify零构建文档站完全指南:从快速搭建到企业级部署
前端·开源·github
weixin_471383034 小时前
Taro-02-页面路由
前端·taro