This time I will show you how to build a webpack environment with vue and node. What are the precautions for building a webpack environment with vue and node. The following is a practical case, let's take a look.
1. Environment setup
Go to the official websiteInstallationnode.js(http://www.runoob.com /nodejs/nodejs-install-setup.html )
Pay attention to the version of node. Only node that supports harmony mode will support es6, and no error will be reported when building the project name based on webpack. Recommend the latest version.
After downloading the installation package, just click Install.
Use npm to install webpack. The command line statement is npm install webpack -g. The interface for successful test installation is as follows:
The next step is to install vue-cli globally. It should be noted that it takes a long time to install vue-cli using npm, which may take more than two hours
The installation statement is: npminstall--globalvue-cli
Create a new project based on webpack template
The command line statement is vue init webpack my-project (where my-project is the file name, and the file name can only be lowercase letters). When creating a new template project, you need to go to the specified folder.
Enter vue init webpack my-project (project folder name) in cmd, press Enter, wait for a short while, the items under 'git' will appear one after another,
is created When working on a new project, if the following error is reported, it means that the node version is too low and does not support the harmonious mode (probably it means that it supports es6, f otherwise it does not support it. You need guidance from an expert for details) and should be replaced with a higher version of node. The error is as shown below:
In cmd 1). Enter: cd my-project (project name), press Enter, enter the specific project folder
Enter: cnpm install, press Enter, wait for a while
Return to the project folder and you will find that there is an additional node_modules folder in the project structure (the contents of this file are the previously installed dependencies)
webstorm installation, project introduction
Go to the official website to download the webstrom installation package and install it.
Keep going next. Depending on your computer system, choose to install a 64-bit system or a 32-bit system. Select js, css, html àjetbrainsà and then install
Select open under file in webstorm (select your project folder)
It looks very simple, but I'm afraid I'll make a mistake in a few days.
Whether the test environment is set up successfully
Method 1: Enter in cmd: cnpm rundev
(Obviously every time you modify the code, it is a very cumbersome process to go to cmd and enter commands every time, so bring up the npm menu in webstorm.
Right-click on the package.json file -> click show npm scripts to bring up the menu. To run in the future, just double-click dev.
in the npm menu. Note that the command line running project and the dev running project cannot be run together. When running one, you need to close the other, otherwise an error that the port is occupied will be reported.
)
Method 2: Enter in the browser: localhost:8080 (the default port is 8080)
If you enter the run command, an error will be reported. There are two situations, as shown in the figure below:
The first situation: port occupation problem
Then the solution is:
Option 1: Close the port during the process.
a. Open cmd and enter the command netstat –ano. All port numbers will appear,
b. Below the local address is the port number, and the PID is the process number of a program that occupies the port number (remember the process number)
c. Open the task manager (ctrl alt delete), click Process, then click View, select "Select Column", click OK and you will find the process program occupying the port
d. Find the remembered process number and close
Option 2: In the config/index.js file, modify the port number. Port: New port number.
Second type: The npm version is too low and needs to be upgraded:
solution:
a. Enter the command: npm install -g npm
b. Copy the files under C:Users{your Windows username}AppDataRoamingnpmnode_modulesnpm to node_modulesnpm in your NodeJS installation directory, overwriting all the original files
(Or use the method of comparing benzene and go through the previous steps again)
2. Changes based on personal needs
1. vue.js changes the default port number 8080 to the specified port:
Executing npm run dev actually calls package.json
in the root directory. After opening package.json, you can find this piece of code
"scripts":{ "dev":"nodebuild/dev-server.js", "build":"nodebuild/build.js", "lint":"eslint--ext.js,.vuesrc" }
From this we can see that we should check the dev-server.js file in the build directory
can be found in the dev-server.js file varuri='http://localhost:' port
The port here is what we are looking for. At the beginning of dev-server.js we can find
varpath=require('path')
And where does path come from?
There is a config folder in the root directory. You can tell by the name that it is related to configuration. Open index.js
dev:{ env:require('./dev.env'), port:8080, autoOpenBrowser:true, assetsSubDirectory:'static', assetsPublicPath:'/', proxyTable:{}, cssSourceMap:false }
in the config directory. Not only can the port be changed here, but other configuration information can also be changed as needed.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use timer to implement countdown function in js
How to invalidate the tag selected="selected" attribute deal with
The above is the detailed content of How to build a webpack environment with vue and node. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor