What should I do if nginx deploys vue and cannot find the js css file?

WBOY
Release: 2023-06-03 10:05:25
forward
1359 people have browsed it

nginx部署vue找不到js css文件怎么办

Many times afternpm run build, the relative directory of the js file and css file automatically inserted by webpack in theindex.htmlfile is always wrong. , after publishing to the server, nginx cannot find the file.

vue-cli@3

In vue-cli@3 you need to insert all the files intoindex.htmlfor your webpack Add abaseurl. You need to create a new one in the root directory of the projectvue.config.js, add the following content:

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

What you need to pay attention to here is the dev environment No need to addbaseurl.

vue-cli@2

For projects generated by non-vue-cli@3, if you don’t care about how webpack is implemented, you only need to findconfig/index.js, just modifyassetspublicpathinbuild.

In order to verify whether it is feasible, you can build it locally, and then check whether the path of the js css file referenced indist/index.htmlcarries theassetspublicpath you just setThat’s it.

For students who are concerned about why this setting is enough, continue to look at thebuild/webpack.base.conf.jsfile,


nginx部署vue找不到js css文件怎么办

In non-productionmode, it is set inconfig/index.js, where thepublicpathdefaults to


nginx部署vue找不到js css文件怎么办

The above is the detailed content of What should I do if nginx deploys vue and cannot find the js css file?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!