【发布时间】:2018-06-20 00:54:17
【问题描述】:
我正在使用 vuejs cli webpack 模板。 我的 URL 不能正常工作,例如:
<link rel="..." href="/static/img/favicons/apple-icon-57x57.png">
这在我的开发服务器上运行良好,但在我的生产服务器上运行良好 ->(未找到 404 文件)。
如果我在我的开发服务器上尝试这个:
$.ajax({
type: 'POST',
url: '/static/php/process.php',
data: term_formData
})
(main.js), url 不工作。(404 文件未找到)
我已经更改了 webpack 选项:assetsPublicPath。
Webpack config/index.js 文件:
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/vueapp/dist/',
...
生产服务器:http://localhost/vueapp/dist/
开发服务器:http://localhost:8080/
提前致谢 =)
【问题讨论】:
-
assetsSubDirectory: './static'。发生这种情况是因为您没有将应用程序放置在模板假定的 Web 根目录中。另一种解决方案是在 Apache/Nginx 配置中将vueapp/dist设为您的 Web 根目录。 -
啊,好的,非常感谢:)