[英]Assets only correctly map up when my application isn't hosted on a pre-existing path
I'm developing an application for use on multiple client sites. 我正在开发一个可在多个客户端站点上使用的应用程序。 These are hosted either as a subdomain or as a path (which I have no control over), like so:
这些托管为子域或路径(我无法控制),如下所示:
Here is my Webpack 1 config: 这是我的Webpack 1配置:
module: {
loaders: [
{
...
},
{
test: /\.(woff2?|eot|svg|ttf|md|jpg|png)$/,
loader: 'file?name=[hash].[ext]'
}
]
},
output: {
path: __dirname + "/dist/build/",
filename: "app.min.js"
}
With this, my assets get compiled into a /build/
folder which also contains the main application JavaScript file: 这样,我的资产就会被编译到
/build/
文件夹中,其中还包含主要的应用程序JavaScript文件:
The issue I'm having is that the compiled assets aren't found if the application is hosted on a pre-existing path (URL example 2 above) but load perfectly fine if no path exists. 我遇到的问题是,如果应用程序托管在预先存在的路径(上面的URL示例2)上,则找不到已编译的资产,但是如果不存在路径,则加载完全正常。 Doing some debugging reveals that for whatever reason the /build directory must be specified for assets to load on the second URL example, but specifying /build breaks the first URL example:
进行一些调试后发现,无论出于何种原因,都必须为资产指定/ build目录才能在第二个URL示例中加载资产,但是指定/ build会破坏第一个URL示例:
What am I doing wrong here? 我在这里做错了什么?
Seems the answer to this is to add the publicPath property to the loader
itself as following: 似乎答案是将publicPath属性添加到
loader
本身,如下所示:
loader: 'file-loader?name=[hash].[ext]&publicPath=./build/'
I had previously attempted this with a separate publicPath
property, but this didn't achieve anything. 之前,我曾尝试使用单独的
publicPath
属性进行此publicPath
,但这并没有实现任何目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.