Vue-cli has been updated recently. When using it to build the project, I found that there are two missing files under the bulid file, namely dev-sever.js and dev-client.js. This article mainly introduces the latest vue-cli 2.9.1 There is a problem with webpack. The editor thinks it is quite good. Now I will share it with you and give you a reference. Let’s follow the editor to take a look, I hope it can help everyone.
vue-cli 2.8
vue-cli 2.9.1
Why is this?
Let’s check package.json
vue-cli 2.8
vue self-starting browser settings
When we started npm run dev to execute this cli, we found that the browser would not start by itself In this case, wouldn’t it be impossible to show off? No, no, it’s still possible, as long as we modify the configuration itemsLet’s first see what our npm run dev executesThe difference from running npm run dev before may explain the reason why he wants to delete these two files, because the configuration of the latest version of webpack uses the webpack-dev-server plug-in to start browsing. You can view one of its API usage instructions on the official website build/webpack.dev.conf.js and check its configuration under the running path vue-cli 2.9.1 build/webpack .dev.conf.js
Hungry? APP interface setting problem
Since the two files in the bulid folder are not available, how to set the Hungry.me interface? Before we understand the setting principle of the interface of the Are you hungry app? Since the data is obtained directly from the data.json file, we need to simulate a mock to make an interface. But in the settings of the Hungry? APP, the interface is ready when the service is started directly. This is why we can directly access its /api/seller and have corresponding dataMethod 1:
Go back to the starting point and configure the latest version of vue-cli The browser services are all in the webpack-dev-server plug-in, then we will modify it in webpack.dev.conf.js is the solution to the problem. Make modifications
webpack.dev.conf.js
So we can send API request data directly
this.axios.get("/api/seller").then(function(res){ // do something })
Method 2
If you know node, you can also make an api interface directly, enable the node service, and then the Are You Hungry project directly access this interface? Of course, there will be cross-domain issues and route mapping here, but webpack-dev-server can help you solve this problem. It mainly involves setting parameters, devServer.proxy, routing mapping, etc.
However, you still need to consider your own abilities. I recommend using the first method
Summary
Front-end technology updates so fast, we’d better do it every day To learn the corresponding knowledge, the main thing is that if the bottom layer can understand these problems thoroughly, we can solve them accordingly.
Related recommendations:
How to use vue-cli to develop multi-page applications
vue-cli quickly builds vue applications and implements webpack Detailed explanation of packaging
How to use vue-cli to build vue projects and webpack?
The above is the detailed content of Detailed explanation of webpack problems in vue-cli 2.9.1. For more information, please follow other related articles on the PHP Chinese website!