Lui*_*nne 6 javascript localhost npm webpack vue.js
我一直在尝试将使用 Vue CLI/Webpack 构建的简单 VueJS 应用程序运行到我的本地主机中,而不必使用 npm run dev,而只能通过从我的本地服务器进行访问。我运行 npm run build 并将文件拖到我在 Mamp 上的 htdocs 中,但它似乎仍然不起作用。这是我在项目中的目录结构:
这是我的根文件夹中的 index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>demo</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是 dist 文件夹中的 index.html
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<title>demo</title>
<link href=/static/css/app.e1c36c05dd8e70649268723708cfb519.css rel=stylesheet>
</head>
<body>
<div id="app"></div>
<script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js>
</script><script type=text/javascript src=/static/js/vendor.3fae27b6d0a0572472a3.js></script>
<script type=text/javascript src=/static/js/app.e5eb3a5fa6134479362c.js></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
谢谢!
1 - npm run build
2 - 复制 build dist 文件夹或 dist index.html
3 - 在 htdocs 中创建一个新文件夹 test
4 - 前往 localhost/test
如果事情不起作用,请在文本编辑器中查看源代码并更改 src 文件的路径,并可能添加基本 href。您的代码显示/static/
我会替换
<script type=text/javascript src=/static/js/app.e5eb3a5fa6134479362c.js></script>
Run Code Online (Sandbox Code Playgroud)
这对
<script type=text/javascript src="http://localhost/test/static/js/app.e5eb3a5fa6134479362c.js"></script>
Run Code Online (Sandbox Code Playgroud)
还要检查控制台错误。