jquery gh-page hosting Parcel v2构建的项目包含静态图像资源,这些资源在运行时不会显示

r6vfmomb  于 5个月前  发布在  jQuery
关注(0)|答案(1)|浏览(66)

项目网站托管在https://bigyajuu.github.io/my-portfolio/上。有问题的图像应该通过以下可点击的容器查看:x1c 0d1xx 1c 1d 1x
在将我的项目部署到gh-page时,jQuery动态处理的图像会显示错误。
我在我的项目中使用纯TS/JS-HTML-CSS,使用Parcel v2捆绑。
当Parcel构建时,reporter插件parcel-reporter-static-files-copy会自动将我的资产文件夹img/移动到dist/文件夹中,希望构建时可以正确找到图像路径。但图像仍然不会显示。
项目目录可以总结如下:

\
    .github\
    .parcel-cache\
    dist\
        img\ (outside img\ moves to here when built)
        ... (where built items lie)
    img\ (asset folder)
    src\ (source codes)
    node_modules\
    .parcelrc
    .package.json
    .package-lock.json

字符串
为了说明,jQuery处理我的图像的方式如下:(/src/ts/engine/mixin-components/overview-dialog.ts)

$slideshow
    .append(
        $('<img>')
            .attr({
            'src': this.images[i].path,
            'title': this.images[i].title,
        })
    .addClass('x-scrollable-item-slideshow')
);


然后$slideshow附加到另一个元素,这将替换HTML中的另一个元素。
package.json scripts:.

"scripts": {
    "build": "parcel build src/index.html",
    "open": "parcel src/index.html --open",
    "live": "npm run build && npm run open",
    "predeploy": "parcel build src/index.html --public-url ./ && cp src/.htaccess dist",
    "sass": "sass --watch css",
    "tsc_watch": "tsc -w"
}


在开发过程中,我运行npm run live:1234上构建和打开网站。那里的图像可能能够显示,可能是在我清除所有缓存之后。
当部署到gh-page时,会运行predeploy。这次不会显示图像。
当检查元素时,gh-page在控制台中返回GET https://bigyajuu.github.io/img/works/<any images> 404 (Not Found)
我们的目标是让图像显示在现场gh-page构建。
当我能够使图像显示在本地环境中的其他尝试是运行parcel build src/index.html img/**。但我真的不太明白这个命令是如何工作的。
整理静态资产对我来说是一个巨大的混乱了几个月,希望有人能帮助。谢谢!

uemypmqf

uemypmqf1#

我自己的问题就这么简单地解决了...
原来dist/文件夹是由托管在https://bigyajuu.github.io/my-portfolio/上的Parcel构建的。
但是我把图像文件的根设置为/,这只指向https://bigyajuu.github.io/
要更正路径,您需要确保根目录是./,仅此而已。
例如:./img/something/somethingElse.png
至于为什么这些镜像在开发环境中正常工作的原因--它们当然可以。它是localhost:1234。根目录可以有一些回旋余地。
并记住随时检查检查元素。

相关问题