2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
If you haven't installed Node.js and npm yet, you can install them fromNode.js official websiteDownload and install the latest version of Node.js. npm will be installed along with Node.js.
Open a command prompt or PowerShell and run the following command to install Yarn globally:
npm install -g yarn
After the installation is complete, run the following command to verify that Yarn is installed successfully:
yarn --version
Navigate to your project directory in the Command Prompt or PowerShell and run the following command to initialize a new Yarn project:
yarn init
Fill in the relevant information of the project according to the prompts, and apackage.json
document.
For example, addreact
andreact-dom
rely:
yarn add react react-dom
If you already have onepackage.json
File, run the following command to install all dependencies:
yarn install
Navigate to your project directory in Command Prompt or PowerShell and run the following command to open VS Code:
code .
You can run Yarn commands in VSCode's integrated terminal. For example, to install new dependencies:
yarn add <package-name>
You can configure tasks in VSCode to run Yarn commands. Create or edit the.vscode/tasks.json
File, add the following configuration:
{
"version": "2.0.0",
"tasks": [
{
"label": "Yarn Install",
"type": "shell",
"command": "yarn install",
"group": "build",
"problemMatcher": [],
"detail": "安装项目所有依赖"
},
{
"label": "Yarn Add",
"type": "shell",
"command": "yarn add",
"args": [
"${input:packageName}"
],
"group": "build",
"problemMatcher": [],
"detail": "添加新的项目依赖"
}
],
"inputs": [
{
"id": "packageName",
"type": "promptString",
"description": "请输入要添加的依赖包名"
}
]
}
In this configuration file, you can pressCtrl+Shift+B
Shortcut key to run the configured task.
Create or edit the project root directory.vscode/launch.json
File, add the following configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/app.js",
"preLaunchTask": "Yarn Install",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}
This will be run automatically before starting debugging.Yarn Install
Task.
You canpackage.json
Define the script in a file and run it in the integrated terminal of VSCode. For example:
{
"scripts": {
"start": "node app.js",
"build": "webpack --config webpack.config.js"
}
}
Run the script:
yarn start
yarn build