首页 \ 问答 \ 保持任务咕噜声任务打开(Keep a task grunt task open)

保持任务咕噜声任务打开(Keep a task grunt task open)

我有一个咕噜咕噜的任务,开启了socket-io服务器等等。

我找到了一种方法,通过在它之后运行“监视”任务来保持任务“打开”(即,不会立即退出命令行)。 例如

grunt.registerTask('default', ["mytask", "watch"]);

但是这需要我在Gruntfile中填写一些虚拟数据,例如。

// Not needed...
watch: {
  files: "test/*"
},

那么有没有办法让我的任务保持运行而不必同时使用监视任务?

谢谢


I have a grunt task that kicks off a socket-io server among other things.

I have found a way of keeping the task 'open' (ie, not exiting straight away on the command line) by running the 'watch' task right after it. e.g

grunt.registerTask('default', ["mytask", "watch"]);

But this requires me to fill in some dummy data in the Gruntfile such as.

// Not needed...
watch: {
  files: "test/*"
},

So is there a way to keep my task running without having to use the watch task along with it?

Thanks


原文:https://stackoverflow.com/questions/18041043
更新时间:2023-11-15 11:11

最满意答案

当你将代码分成许多文件时,你需要确保它们在运行时全部加载。

例如:

<script src="Game.js"></script>
<script src="StateTitleScreen.js"></script>
<script src="StateGameRunning.js"></script>
<script src="app.js"></script>

请注意,你的app.js是最后一个(因为它取决于其他人,而且顺序很重要)。

您还可以要求TypeScript使用以下方法为您提供单个文件:

--out combined.js

然后,您可以在页面上引用组合文件,而不是许多单独的文件 - 但您仍然可以在设计时通过分割成多个文件来管理应用程序。


When you split your code into many files, you need to ensure they are all loaded at runtime.

For example:

<script src="Game.js"></script>
<script src="StateTitleScreen.js"></script>
<script src="StateGameRunning.js"></script>
<script src="app.js"></script>

Note that your app.js is last (because it depends on the others and the order matters).

You can also ask TypeScript to supply you with a single file using:

--out combined.js

You can then reference the combined file on your page, rather than many individual files - but you still get to manage your application by splitting into many files at design time.

相关问答

更多
  • .map文件是源映射文件,可以让工具在发布的JavaScript代码和创建它的TypeScript源文件之间进行映射。 许多调试器(例如Visual Studio或Chrome的开发工具)可以使用这些文件,以便您可以调试TypeScript文件而不是JavaScript文件。 这是由一些细分器和其他编译到JS语言(如CoffeeScript)生成的源地图格式。 .map files are source map files that let tools map between the emitted Jav ...
  • 更新 TypeScript 1.8+: "use strict"; 在模块中发射( 阅读更多 )。 TypeScript 2.1+:-- --alwaysStrict编译器选项以严格模式解析所有文件,并在所有输出文件的顶部发出"use strict" ( 阅读更多 )。 您可以通过搜索“严格模式”中的TypeScript测试来找到一些示例的列表。 这里有一些代码,只会在"use strict";时抛出编译时错误"use strict"; : // future reserved keyword not al ...
  • 当你将代码分成许多文件时,你需要确保它们在运行时全部加载。 例如: 请注意,你的app.js是最后一个(因为它取决于其他人,而且顺序很重要)。 您还可以要求TypeScript使用以下方法为您提供单个文件: ...
  • From: // THROWS ERROR "JavaScript runtime error: Object doesn't support this action" 显然, 排序是错误的 。 使用outFile指定排序 你可以使用好的reference文件技巧。 这里有很好的记录: https: //github.com/TypeStrong/grunt-ts#javascript-generation? PS:我相信你知道我对这个问题的看法: https : //basarat.gitbooks.io ...
  • 您需要使用browserify才能在浏览器中使用CommonJS模块。 幸运的是,你大部分都在那里。 您只需要使用gulp - browserify和tsify插件替换gulp - typescript gulp-typescript-compiler 。 这是一个Gulpfile示例 var gulp = require('gulp'); var browserify = require('browserify'); var source = require('vinyl-source-stream'); ...
  • 由于您使用的库直接导出函数,您可以像这样输入: declare module 'd3-cloud' { let cloud: Function; export = cloud; } Since the library you use directly exports a function you can type it like this: declare module 'd3-cloud' { let cloud: Function; export = cloud; }
  • 你的代码编译好我。 这是我有的: GameModule.ts export module GameModule { export class Game { private boardContainer: HTMLElement; private board: number[][]; constructor (container: HTMLDivElement) { this.boardContainer = container ...
  • 您需要让TypeScript了解外部库。 最简单的方法是通过DefinitelyTyped 。 此链接将带您进入TypeScript的require.js deffinitions。 .d.ts文件用于让TypeScript了解通过库提供的API,更多信息请点击此处 。 您可以通过VisualStudio中的nuGet获取任何definitelyTyped定义文件。 /// 在VS ...
  • 您的脚本引用应该如下所示(顺序很重要......而.js文件扩展名也很重要!) Your script references should look like this (order is important... and .js file extension is important too!)