【发布时间】:2017-09-15 10:25:50
【问题描述】:
由于生产和开发结构不同,我在 vue 2 项目(webpack-simple 模板)中提供快速静态数据时遇到问题。
发展: 本地主机/应用程序
生产: 服务器/某些目录/应用程序
some-directory 经常更改,因此它是在配置文件中动态设置的。
我的 server.js 服务部分:
if (config.root !== '/') {
app.use(`/${config.root}`, express.static(path.join(__dirname)));
}
app.use('/dist', express.static(path.join(__dirname, 'dist')));
转译后的 JS 文件在 /dist 文件夹中。
这是作为应用入口点的 index.html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App Demo</title>
</head>
<body>
<div id="app"></div>
<script src="/dist/build.js"></script>
</body>
</html>
它在开发中有效,因为应用程序位于根目录中。
但在生产构建中它不起作用,因为应用程序是从服务器子文件夹提供的。
有什么办法解决这个问题吗?
谢谢。
【问题讨论】: