Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx deployment vue project can not find the js css file how to solve the problem

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the "nginx deployment vue project can not find js css files how to solve" related knowledge, editor through the actual case to show you the process of operation, the method of operation is simple and fast, practical, hope that this "nginx deployment vue project can not find js css files how to solve" article can help you solve the problem.

Many times after npm run build, the relative directory of the js file css file that webpack automatically inserts in the index.html file is always wrong. After publishing to the server, nginx can not find the file.

Vue-cli@3

In vue-cli@3 you need to add a baseurl for all files that you webpack insert into index.html. You need to create a new vue.config.js in the root directory of the project and add the following:

... module.exports = {baseurl: isprod?'/ basexxx/':'/',....}

It is important to note that there is no need to add baseurl in the dev environment.

Vue-cli@2

For non-vue-cli@3-generated projects, if you don't care about how it is implemented in webpack, you just need to find the config/index.js and modify the assetspublicpath in the build.

To verify whether it is feasible, you can build locally, and then check to see if the path to the js css file referenced in dist/index.html carries the assetspublicpath you just set.

For those of you who are concerned about why this setting is OK, continue to look at the build/webpack.base.conf.js file.

If it is not production mode, it is set in config/index.js. The default publicpath here is

This is the end of the content about "nginx deployment vue project can not find the js css file". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report