vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
12.79k stars 2.07k forks source link

Why the css and js files import fail after I build? In other words, the styles are lost and the web pages are messed up. #4165

Open rosa5500 opened 1 month ago

rosa5500 commented 1 month ago

Why the css and js files import fail after I npm run build? In other words, the styles are lost and the web pages are messed up.

Whether or not to set base is the same.

The following is the dist without the base (taking example.html as an example):

image image image

As long as I change "href="/assets/style.eGqldYn-.css" to href="assets/style.eGqldYn-.css", the style will return to normal.

image

Is there something wrong with the config.ts?

thanks very much~


为什么我build之后,css和js文件的引入失败呢?也就是说,样式丢失,网页错乱

无论加不加base属性都是如此。

以下是没有加base属性的dist文件(以example.html为例):

image image image

只要我将 href="/assets/style.eGqldYn-.css" 改成 href="assets/style.eGqldYn-.css",样式就恢复正常了。

image

是哪里的配置写错了吗?

非常感谢

brc-dd commented 1 month ago

How are you serving the generated files? Directly opening html files in browser won't work. Run npm run docs:preview (vitepress preview docs).

rosa5500 commented 1 month ago

How are you serving the generated files? Directly opening html files in browser won't work. Run npm run docs:preview (vitepress preview docs).

How do I deploy on Jenkins? At present, I have put the dist file generated by build into the server. Opening the page results in a distorted style. Additionally, npm run docs: preview is correct locally. Thank you.

Jenkins deployment command

image
brc-dd commented 1 month ago

Do you see any errors on console or network tab in browser dev tools?

rosa5500 commented 1 month ago

Do you see any errors on console or network tab in browser dev tools?

On the website:

image
rosa5500 commented 1 month ago

Do you see any errors on console or network tab in browser dev tools?

Do you see any errors on console or network tab in browser dev tools?

Right click to view webpage source code:

image
rosa5500 commented 1 month ago

Do you see any errors on console or network tab in browser dev tools?

Very strange. The same code, I will have an additional "/" locally, while the website only has one "/ "normally, but it also failed to import

image
brc-dd commented 1 month ago

In your last image it's showing file:// urls that means you've opened your html directly which isn't and won't be supported.

In image before that it's not able to load those files. I've never used jenkins so can't comment much, but you said that removing / works, does it works in jenkins too? If so, then your base might be wrong. How do you deploy a normal html,css site to jenkins?