假设这是我的服务器结构:
www
source
main.js
assets
img1
img2
siteLink1
index.html
siteLink2
index.html
在两个 html 中,我<script src='../source/bundle.js'/>
都有两个链接,它们具有相同的 JS 源。
问题是它bundle.js
包含所有的css,它们有一些类似的东西:
.bg{
background: url(img1.jpg)
}
然后,webpacked JS 添加<style>
说:
.bg{
background: url(./assets/img1.jpg)
}
这很好,如果 JS 和 HTML 在同一个地方,但由于它们不是,style
in html 指向不存在的相对assets
文件夹。
所以我真正需要的是对 JS 说 - 当你放置style
带有所需的所有 css 的标签时css-loader
,使其相对于 JS 的位置,而不是 HTML 的位置。
我能做些什么?