About the new VUE-CLI installation Json-server The Dev-server file is not generated in the build file

Source: Internet
Author: User

There was a problem installing json-server today, and the build file did not generate a dev-server.js file.

Start is suspected configuration has a problem, or is not installed correctly, then reinstalled two or three times, or so, depressed.

By querying the information, the new version of the VUE-CLI canceled Dev-server.js and dev-client.js instead of webpack.dev.conf.js instead, so configure local access in Webpack.dev.conf.js configuration can be

Open Webpack.dev.conf.js, (in the build directory),

Add the following two lines of code after const Portfinder = require (' Portfinder ')

Const APPDATA = require ('./db.json ')//load Local data file, this Db.json is your own custom new file name, store the path with you, I put the test in the build directory, and finally to explain this Db.json
CONST SELLER = appdata.seller//Gets the corresponding local data,

Add the above code to continue to find devserver:{} in this file

Add a configuration to this object (do not delete or overwrite the value of the previous default configuration)

For example: (here directly copy the code of the predecessor)

Before (APP) {
App.get ('/api/seller ', (req, res) = {
Res.json ({

errno:0,

Data:seller

})
})
},

Then, the question came,

1. Where is my own JSON data written in the Db.json I created myself, I went to try it, useless ... Embarrassed!

2, according to the above configuration is finished, browse Localhost:8080/api/seller refresh the browser did not respond

3, Localhost:8080/api/seller has responded to the result returned {"Erron": 0}

Solve

1. For the 1th question, after their own repeated testing, Db.json inside must have a pair of empty {}, of course, can also write some data in, although not error, but also do not know what role (I have a piece of cake, also did not too much to study), but not {} must be an error

2. For the 2nd, the browser does not respond to the problem, be sure to remember, when every change webpack.dev.conf.js this file or Db.json file, remember to re-npm run dev

3. For the 3rd, believe that the basic person has been seen, the browser returned {"Erron": 0} is actually configured above

Res.json ({

errno:0,

Data:seller

})

errno:0, then replace it with his JSON data.

Res.json ({

"Getnewslist": [
{
"id": 1,
"title": "News Item 1 News item 1 News item 1 News item 1",
"url": "Http://starcraft.com"
},
{
"id": 2,
"title": "News Item 2 News item 2 News item 2 News item 2",
"url": "Http://warcraft.com"
},
{
"id": 3,
"title": "News article 3 News article 3 News article 3",
"url": "Http://overwatch.com"
},
{
"id": 4,
"title": "News article 4 ad release",
"url": "Http://hearstone.com"
}
],

Data:seller

})

Finish

About the new VUE-CLI installation Json-server The Dev-server file is not generated in the build file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.