Javascript 运行MEANJS工作流的Visual Studio代码配置

Javascript 运行MEANJS工作流的Visual Studio代码配置,javascript,visual-studio-code,Javascript,Visual Studio Code,我刚刚安装了Visual Studio代码,并试图在IDE中运行我的应用程序,VisualStudio创建了一个带有launch.json文件的./settings文件夹,其中包含运行项目的配置 我通常使用MEANJS工作流只需在应用程序的根文件夹中键入grunt,并使用命令调用GrunFile.js,其中包含启动应用程序的所有作业 我想在VisualStudio代码中尝试通过按play按钮来实现同样的效果,并运行grunt任务,但我不知道从哪里开始 { "version": "0.1.

我刚刚安装了Visual Studio代码,并试图在IDE中运行我的应用程序,VisualStudio创建了一个带有launch.json文件的./settings文件夹,其中包含运行项目的配置

我通常使用MEANJS工作流只需在应用程序的根文件夹中键入grunt,并使用命令调用GrunFile.js,其中包含启动应用程序的所有作业

我想在VisualStudio代码中尝试通过按play按钮来实现同样的效果,并运行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
        }
    ]
}

有什么建议吗?

在task.json文件中替换这些设置

{
"version": "0.1.0",

// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "grunt",

// The command is a shell script
"isShellCommand": true,

// Show the output window only if unrecognized errors occur. 
"showOutput": "silent",

// args is the HelloWorld program to compile.
"args": ["serve"]
}
如果grunt文件中没有“serve”参数,则可以将其忽略

但是,按下绿色启动按钮时,此操作不会运行。 要启动此任务,您需要按

Ctrl+Shift+p

从那里可以使用任务命令

可以使用键盘快捷方式设置和运行任务

更新:我在Visual Studio代码中找不到如何执行此操作,但在WebStread中,这是一个简单的设置,只需单击几下鼠标即可完成。

VSCode示例
您可以使用Visual Studio代码设置任何工作流工具,并使用CTRL+SHFT+p,然后运行并选择任务。您还可以分别使用
CTRL+SHFT+B
CTRL+SHFT-T
设置默认的
BUILD
TEST
任务。只要任务运行程序Gulp、Grunt、Cake或其他设置正确,就可以配置VSCode

您可以在VSCode中按名称设置所有Gulp或其他任务运行程序任务,也可以只设置少数同时运行其他子任务的任务

从VSCode 0.5.0开始,任务参数存在问题,需要在tasks.json文件中反转这些参数。更多信息

请注意,前两个任务将
isBuildCommand
isTestCommand
设置为“true”,允许使用上述键盘快捷键。从VSCode 0.5.0开始,最后一个任务需要有
参数
命令
名称
反转
,才能工作。看这个

使用VSCode调试
您可以使用VSCode调试器运行Node.js应用程序并启动
播放
按钮并用
圆形箭头重新启动
。为此,您需要配置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
    },
正在运行节点应用程序
您还可以使用Gulp或其他任务运行程序启动和自动重新启动node.js应用程序。我更喜欢Gulp,因为它的代码多于配置设置,而且它本身就使用流

还有另一个名为gulp.config.js的文件,它由gulp.js引用,其中包含各种静态变量和函数,这些变量和函数没有显示出来,因此在整个gulpfile.js中都引用了config。以下是require声明:

//require containing config variables and run
 var config = require('./gulp.config.js')();
下面是一个gulpfile.js,我在参加John Papa教授的课程时使用它。在配置中定义了许多任务,包括Gulp Task
service-DEV
,它运行节点服务器应用程序,在js上自动重新启动服务器,css或html更改和同步多个浏览器视图,注入css和js,编译更少,以及其他任务

GULP文件的GIST链接

Gulp文件太复杂,无法由堆栈溢出标记进行解释,因此我添加了这个

谢谢你的回复,我有一个问题,在不显式运行命令的情况下,如何在自动调试应用程序之前运行2或3个任务?
//require containing config variables and run
 var config = require('./gulp.config.js')();