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

Visual Studio Code configuration to run MEANJS workflow

我刚刚安装了 Visual Studio Code,我正在尝试 运行 我的 MEANJS 应用程序 IDE, VisualStudio 使用 launch.json 文件创建了一个 ./settings 文件夹,其中包含 运行 项目的配置。

我通常使用 MEANJS 工作流程所做的只是在应用程序的根文件夹中键入 g运行t 和调用 gruntfile.js 其中包含启动我的应用程序的所有作业。

我想尝试通过按下按钮播放和 运行 g运行t 任务在 Visual Studio 代码中实现相同的效果,但我不知道从哪里开始.

{
    "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"]
}

如果您的 g运行t 文件没有 "serve" 参数,您可以省略它。

但是这不会运行按下绿色开始按钮。 要启动此任务,您需要按

Ctrl + Shift + P

从那里您可以使用任务命令。

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

更新: 我没有在 Visual Studio 代码 中找到如何做,但在 WebStorn 设置简单,只需点击几下鼠标。

VSCode 示例


您可以使用 Visual Studio 代码设置任何工作流工具,然后使用 CTRL+SHFT+P 然后 RUN 和 select TASKS。您还可以分别使用 CTRL+SHFT+BCTRL+SHFT-T 设置默认 BUILDTEST 任务。只要任务运行nerGulp、G运行t、Cake等设置正确VSCode就可以配置

您可以在 VSCode 中设置所有 Gulp 或其他任务 运行 中的每个任务的名称,或者仅设置一些 运行 另一个子任务任务。

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

{
"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"
        ]
    },

注意前两个任务 isBuildCommandisTestCommand 设置为 'true' 允许使用上述键盘快捷键。从 VSCode 0.5.0 开始,最后一个任务需要具有 argumentcommand 名称 reversed 才能工作。看到这个 link

正在使用 VSCode 调试


您可以 VSCode 调试 Run Node.js 应用程序和 Start Play 按钮并使用 Circular Arrow 重新启动。为此,您需要配置 launch.json。如果您只想 start/restart 应用程序而不调试,请将 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


您还可以使用 Gulp 或其他任务 运行ner 来启动和自动重启您的 node.js 应用程序等等。我更喜欢 Gulp,因为它是代码而不是配置设置,而且它本质上使用流。

gulp.js 引用了另一个名为 gulp.config.js 的文件,其中包含未显示的各种静态变量和函数,因此在整个 gulpfile.js 中引用了配置。这是要求声明:

//require containing config variables and run
 var config = require('./gulp.config.js')();

以下是我在参加 John Papa 教授的 Plurasight Course 课程时使用的 gulpfile.js。在配置中定义了许多任务,包括 Gulp 任务 SERVE-DEV 其中 运行 是节点服务器应用程序,在 js 上自动重启服务器,css 或 html 更改并同步多个浏览器视图,注入 CSS 和 JS,编译 LESS,以及其他任务。

GIST LINK GULP 文件


Gulp 文件太复杂,Stack Overflow 标记无法解释,所以我添加了这个 GistBox Link