【问题标题】:VueJS CLI Webpack static folder not working when in subfolderVueJS CLI Webpack静态文件夹在子文件夹中不起作用
【发布时间】: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 根目录。
  • 啊,好的,非常感谢:)

标签: webpack vuejs2 vue-cli


【解决方案1】:

设置assetsSubDirectory: './static'。发生这种情况是因为您没有将应用程序放置在模板假定的 Web 根目录中。另一种解决方案是在您的 Apache/Nginx 配置中将 vueapp/dist 设为您的 Web 根目录。

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-11
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多