Home  >  Q&A  >  body text

Webpack - a project written by vue-cli (no problem running locally), is going to be put on the Nginx server. What configuration needs to be changed? How else to deploy?

For a project built locally using Vue-cli, the webpack configuration has not been touched and it runs without any problems locally. However, I plan to put it on the Nginx server. Do I need to change any configuration? Then how to deploy Nginx?

I searched, and some said to change assetsPublicPath in index.js under config: './' (/a/11...)

Some say to add publicPath:'./' (http://blog.csdn.net/gebitan5...) to the output of webpack.prod.conf.js

After trying everything, it still can’t be opened on the server, please help~~~~

高洛峰高洛峰2674 days ago1080

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-05-27 17:46:57

    If it is just Vue, package it through npm run build, and then publish the static files in the dist to the server. In the Nginx configuration, configure the folder pointing to the static files through the location path, which will directly access the file. The index.html file in the folder...

    reply
    0
  • 某草草

    某草草2017-05-27 17:46:57

    If you want to access your built project directly through the domain name, such as hzzly.net, then change assetsPublicPath: '/' in index.js under config. No need to change. If you want to add another layer after the domain name, such as hzzly.net /resume, then change the index.js under config to assetsPublicPath: '/resume/', the following nginx configuration can remain unchanged, just create a new resume folder directly in the main directory of the website.

    server {
            listen       80;
            server_name  localhost;
    
            location / {
                root   /home/hzzly;  //这里配置网站主目录
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }

    reply
    0
  • ringa_lee

    ringa_lee2017-05-27 17:46:57

    Load the homepage, view the HTML file, and check whether the resource reference path is correct.
    Similar to the picture above, check the path in src to see if the resources in your server are correct. If it is incorrect, go to webpack to modify the resource packaging path.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-27 17:46:57

    Is it 404 when accessing js?

    reply
    0
  • Cancelreply