jac*_*per 5 javascript visual-studio-code
我刚刚安装了Visual Studio Code,我正在尝试在IDE中运行我的MEANJS应用程序,VisualStudio创建了一个带有launch.json文件的./settings文件夹,其中包含运行项目的配置.
我通常使用MEANJS工作流程只是在应用程序的根文件夹中键入grunt,并调用gruntfile.js命令,该命令包含启动我的应用程序的所有作业.
我想通过按下按钮播放尝试在Visual Studio Code中实现相同的功能,并运行grunt任务,但我不知道从哪里开始.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch Project",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "gruntfile.js",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": [],
// Environment variables passed to the program.
"env": { },
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 3000,
"sourceMaps": false
}
]
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
您可以使用 Visual Studio Code 设置任何工作流工具,CTRL+SHFT+P然后使用RUN并选择TASKS. 您还可以分别使用和设置默认值BUILD和TEST任务。只要任务运行器 Gulp、Grunt、Cake 或其他设置正确,就可以配置 VSCode。CTRL+SHFT+BCTRL+SHFT-T
您可以在 VSCode 中按名称设置所有 Gulp 或其他任务运行器任务,或者仅设置几个也运行其他子任务的任务。
从 VSCode 0.5.0 开始,任务参数存在问题,需要在tasks.json 文件中反转它们。更多信息请点击此处
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "vet",
"isBuildCommand": true,
"isTestCommand": false,
"showOutput": "always",
"args": [],
"problemMatcher": [
"$jshint",
"$jshint-stylish"
]
},
{
"taskName": "vet-es",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"args": [],
"problemMatcher": [
"$eslint-compact",
"$eslint-stylish"
]
},
{
"taskName": "--verbose",
"isBuildCommand": false,
"isTestCommand": false,
"showOutput": "always",
"args": [
"vet"
],
"problemMatcher": [
"$jshint",
"$jshint-stylish"
]
},
Run Code Online (Sandbox Code Playgroud)
请注意,前两个任务已将isBuildCommand和isTestCommand设置为“true”,这允许使用上面提到的键盘快捷键。从 VSCode 0.5.0 开始,最后一个任务需要有argument和commandnamereversed才能工作。请参阅此链接。
您可以使用 VSCode 调试器调试RunNode.js 应用程序,然后Start使用
Play按钮重新启动Circular Arrow。为此,您需要配置 launch.json。如果您只想启动/重新启动应用程序而不进行调试,则设置stoponentry为 false。我通常有两个,一个用于调试,一个用于运行。
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Debug src/server/app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "src/server/app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": [],
// Environment variables passed to the program.
"env": { },
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Run src/server/app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "src/server/app.js",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": [],
// Environment variables passed to the program.
"env": { },
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
Run Code Online (Sandbox Code Playgroud)
您还可以使用 Gulp 或其他任务运行程序来启动和自动重新启动您的 Node.js 应用程序以及许多其他功能。我更喜欢 Gulp,因为它的代码优于配置设置,而且它本质上使用流。
还有另一个名为 gulp.config.js 的文件,由 gulp.js 引用,其中包含未显示的各种静态变量和函数,因此在整个 gulpfile.js 中对配置的引用。这是要求声明:
//require containing config variables and run
var config = require('./gulp.config.js')();
Run Code Online (Sandbox Code Playgroud)
以下是我在参加John Papa 教授的Plurasight 课程时使用的 gulpfile.js 。在配置中定义了许多任务,包括SERVE-DEV运行节点服务器应用程序的 Gulp 任务、在 js、css 或 html 更改时自动重新启动服务器并同步多个浏览器视图、注入 CSS 和 JS、编译 LESS 等任务。
Gulp 文件太复杂,无法由 Stack Overflow 标记解释,因此我添加了此GistBox Link。
| 归档时间: |
|
| 查看次数: |
799 次 |
| 最近记录: |