【问题标题】:Cannot find specific paths when going from local to server从本地到服务器时找不到特定路径
【发布时间】:2018-10-30 08:22:03
【问题描述】:

我正在尝试使用来自本地主机和服务器的图标/字体。 我的项目结构如下: https://files.gitter.im/webpack/webpack/7XUh/image.png (因为我还没有 10 声望,所以无法插入图片。)

我已经定义了资产→图像→徽标地图中的所有图标。 webpack.config.js 中的 baseUrl 定义为“./”。

我正在尝试使用 my-notifications.scss 中的以下图标: 背景:白色 url(/../../assets/images/logos/sample-logo.svg) 右 15px center no-repeat;

这在我的本地主机上工作。但是,如果我在服务器上打开我的客户端,它就找不到 svg 文件。 控制台中的错误输出如下: GET http://server/assets/images/logos/sample-logo.svg 404(未找到)

要导航到服务器上的客户端,我将导航到:http://server/company/customername/client2

奇怪的是,我制作了一个带有名称、ID 和图像源的 TypeScript 模型。我在我的应用程序的另一个地方使用这个图像源(this.imagesrc = './assets/images/logos/sample-image'),并且图像源在那里工作,在本地主机和服务器上。

有人知道如何解决这个问题吗?

谢谢。

【问题讨论】:

    标签: javascript typescript webpack aurelia webpack-4


    【解决方案1】:

    静态文件从您的输出路径提供,但您需要将公共路径指定为服务器:

    http://server/company/customername/client2 您需要将其添加到生成的捆绑包中。您可以在 publicPath 中定义它: output: { publicPath: `http://server/company/customername/client2` },

    那么您在生产中的资产将由http://server/company/customername/client2/assets/images/logos/sample-logo.svg提供服务

    如果您使用 CDN,您还可以在运行时生成资产。参考:https://webpack.js.org/concepts/output/#advanced

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 2013-09-20
      • 1970-01-01
      • 2019-05-17
      • 2020-08-10
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多