{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/gulp.html","result":{"data":{"allSitePage":{"nodes":[{"path":"/dev-404-page/"},{"path":"/docs/handbook/advanced-types.html"},{"path":"/docs/handbook/basic-types.html"},{"path":"/docs/handbook/classes.html"},{"path":"/docs/handbook/compiler-options-in-msbuild.html"},{"path":"/docs/handbook/compiler-options.html"},{"path":"/docs/handbook/configuring-watch.html"},{"path":"/docs/handbook/declaration-merging.html"},{"path":"/docs/handbook/decorators.html"},{"path":"/docs/handbook/enums.html"},{"path":"/docs/handbook/functions.html"},{"path":"/docs/handbook/generics.html"},{"path":"/docs/handbook/integrating-with-build-tools.html"},{"path":"/docs/handbook/interfaces.html"},{"path":"/docs/handbook/iterators-and-generators.html"},{"path":"/docs/handbook/jsdoc-supported-types.html"},{"path":"/docs/handbook/jsx.html"},{"path":"/docs/handbook/literal-types.html"},{"path":"/docs/handbook/mixins.html"},{"path":"/docs/handbook/module-resolution.html"},{"path":"/docs/handbook/modules.html"},{"path":"/docs/handbook/namespaces-and-modules.html"},{"path":"/docs/handbook/namespaces.html"},{"path":"/docs/handbook/nightly-builds.html"},{"path":"/docs/handbook/project-references.html"},{"path":"/docs/handbook/symbols.html"},{"path":"/docs/handbook/"},{"path":"/docs/handbook/triple-slash-directives.html"},{"path":"/docs/handbook/type-checking-javascript-files.html"},{"path":"/docs/handbook/type-compatibility.html"},{"path":"/docs/handbook/type-inference.html"},{"path":"/docs/handbook/unions-and-intersections.html"},{"path":"/docs/handbook/utility-types.html"},{"path":"/docs/handbook/variable-declarations.html"},{"path":"/docs/handbook/writing-declaration-files.html"},{"path":"/docs/handbook/declaration-files/by-example.html"},{"path":"/docs/handbook/declaration-files/consumption.html"},{"path":"/docs/handbook/declaration-files/deep-dive.html"},{"path":"/docs/handbook/declaration-files/do-s-and-don-ts.html"},{"path":"/docs/handbook/declaration-files/introduction.html"},{"path":"/docs/handbook/declaration-files/library-structures.html"},{"path":"/docs/handbook/declaration-files/publishing.html"},{"path":"/docs/handbook/declaration-files/templates.html"},{"path":"/docs/handbook/release-notes/typescript-1-1.html"},{"path":"/docs/handbook/release-notes/typescript-1-3.html"},{"path":"/docs/handbook/release-notes/typescript-1-4.html"},{"path":"/docs/handbook/release-notes/typescript-1-5.html"},{"path":"/docs/handbook/release-notes/typescript-1-6.html"},{"path":"/docs/handbook/release-notes/typescript-1-7.html"},{"path":"/docs/handbook/release-notes/typescript-1-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-0.html"},{"path":"/docs/handbook/release-notes/typescript-2-2.html"},{"path":"/docs/handbook/release-notes/typescript-2-1.html"},{"path":"/docs/handbook/release-notes/typescript-2-3.html"},{"path":"/docs/handbook/release-notes/typescript-2-4.html"},{"path":"/docs/handbook/release-notes/typescript-2-5.html"},{"path":"/docs/handbook/release-notes/typescript-2-6.html"},{"path":"/docs/handbook/release-notes/typescript-2-7.html"},{"path":"/docs/handbook/release-notes/typescript-2-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-9.html"},{"path":"/docs/handbook/release-notes/typescript-3-0.html"},{"path":"/docs/handbook/release-notes/typescript-3-1.html"},{"path":"/docs/handbook/release-notes/typescript-3-2.html"},{"path":"/docs/handbook/release-notes/typescript-3-3.html"},{"path":"/docs/handbook/release-notes/typescript-3-4.html"},{"path":"/docs/handbook/release-notes/typescript-3-5.html"},{"path":"/docs/handbook/release-notes/typescript-3-6.html"},{"path":"/docs/handbook/release-notes/typescript-3-7.html"},{"path":"/docs/handbook/release-notes/typescript-3-8.html"},{"path":"/docs/handbook/asp-net-core.html"},{"path":"/docs/handbook/angular.html"},{"path":"/docs/handbook/dom-manipulation.html"},{"path":"/docs/handbook/gulp.html"},{"path":"/docs/handbook/migrating-from-javascript.html"},{"path":"/docs/handbook/react-&-webpack.html"},{"path":"/docs/handbook/react.html"},{"path":"/docs/handbook/typescript-in-5-minutes-func.html"},{"path":"/docs/handbook/typescript-in-5-minutes.html"},{"path":"/docs/handbook/typescript-in-5-minutes-oop.html"},{"path":"/docs/handbook/typescript-from-scratch.html"},{"path":"/docs/handbook/typescript-tooling-in-5-minutes.html"},{"path":"/docs/handbook/tsconfig-json.html"},{"path":"/docs/handbook/declaration-files/templates/global-modifying-module-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-class-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-function-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-d-ts.html"},{"path":"/docs/handbook/release-notes/overview.html"},{"path":"/tsconfig"},{"path":"/en/tsconfig"},{"path":"/ja/tsconfig"},{"path":"/vo/tsconfig"},{"path":"/play"},{"path":"/en/play"},{"path":"/es/play"},{"path":"/vo/play"},{"path":"/zh/play"},{"path":"/ja/play"},{"path":"/play/3-7/fixits/big-number-literals.ts"},{"path":"/play/3-7/fixits/const-to-let.ts"},{"path":"/play/3-7/fixits/infer-from-usage-changes.ts"},{"path":"/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/play/3-7/syntax-and-messaging/nullish-coalescing.ts"},{"path":"/play/3-7/syntax-and-messaging/optional-chaining.ts"},{"path":"/play/3-7/types-and-code-flow/assertion-functions.ts"},{"path":"/play/3-7/types-and-code-flow/recursive-type-references.ts"},{"path":"/play/3-7/types-and-code-flow/uncalled-function-checks.ts"},{"path":"/play/3-8/breaking-changes/checking-unions-with-index-signatures.ts"},{"path":"/play/3-8/jsdoc-improvements/accessibility-modifiers.js"},{"path":"/play/3-8/syntax-and-messaging/export-modules-from.ts"},{"path":"/play/3-8/syntax-and-messaging/private-class-fields.ts"},{"path":"/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/play/javascript/external-apis/typescript-with-node.js"},{"path":"/play/javascript/external-apis/typescript-with-web.js"},{"path":"/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/play/javascript/helping-with-javascript/errors.ts"},{"path":"/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/play/javascript/javascript-essentials/functions.ts"},{"path":"/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/play/javascript/modern-javascript/async-await.ts"},{"path":"/play/javascript/modern-javascript/immutability.ts"},{"path":"/play/javascript/modern-javascript/import-export.ts"},{"path":"/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/play/javascript/working-with-classes/classes-101.ts"},{"path":"/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/play/javascript/working-with-classes/mixins.ts"},{"path":"/play/javascript/working-with-classes/this.ts"},{"path":"/play/playground/config/javascript-playgrounds.js"},{"path":"/play/playground/config/new-compiler-defaults.ts"},{"path":"/play/playground/language/automatic-type-acquisition.ts"},{"path":"/play/playground/language/fixits.ts"},{"path":"/play/playground/tooling/mobile-support.ts"},{"path":"/play/playground/tooling/sharable-urls.ts"},{"path":"/play/playground/tooling/typescript-versions.ts"},{"path":"/play/typescript/language/soundness.ts"},{"path":"/play/typescript/language/structural-typing.ts"},{"path":"/play/typescript/language/type-guards.ts"},{"path":"/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/play/typescript/language-extensions/enums.ts"},{"path":"/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/play/typescript/meta-types/conditional-types.ts"},{"path":"/play/typescript/meta-types/discriminate-types.ts"},{"path":"/play/typescript/meta-types/indexed-types.ts"},{"path":"/play/typescript/meta-types/mapped-types.ts"},{"path":"/play/typescript/primitives/any.ts"},{"path":"/play/typescript/primitives/literals.ts"},{"path":"/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/play/typescript/primitives/unknown-and-never.ts"},{"path":"/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/play/typescript/type-primitives/nullable-types.ts"},{"path":"/play/typescript/type-primitives/tuples.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-node.js"},{"path":"/es/play/javascript/external-apis/typescript-with-web.js"},{"path":"/es/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/es/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/es/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/es/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/es/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/es/play/typescript/type-primitives/nullable-types.ts"},{"path":"/es/play/typescript/type-primitives/tuples.ts"},{"path":"/ja/play/typescript/language-extensions/enums.ts"},{"path":"/ja/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/ja/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/ja/play/typescript/primitives/any.ts"},{"path":"/ja/play/typescript/primitives/literals.ts"},{"path":"/ja/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/ja/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/vo/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/vo/play/javascript/javascript-essentials/functions.ts"},{"path":"/vo/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/vo/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-node.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-web.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/zh/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/zh/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/zh/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/zh/play/javascript/helping-with-javascript/errors.ts"},{"path":"/zh/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/zh/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/zh/play/javascript/javascript-essentials/functions.ts"},{"path":"/zh/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/zh/play/javascript/modern-javascript/import-export.ts"},{"path":"/zh/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/zh/play/javascript/working-with-classes/classes-101.ts"},{"path":"/zh/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/zh/play/javascript/working-with-classes/mixins.ts"},{"path":"/zh/play/javascript/working-with-classes/this.ts"},{"path":"/zh/play/playground/config/javascript-playgrounds.js"},{"path":"/zh/play/playground/config/new-compiler-defaults.ts"},{"path":"/zh/play/playground/language/automatic-type-acquisition.ts"},{"path":"/zh/play/playground/language/fixits.ts"},{"path":"/zh/play/playground/tooling/mobile-support.ts"},{"path":"/zh/play/playground/tooling/sharable-urls.ts"},{"path":"/zh/play/playground/tooling/typescript-versions.ts"},{"path":"/zh/play/typescript/language/soundness.ts"},{"path":"/zh/play/typescript/language/structural-typing.ts"},{"path":"/zh/play/typescript/language/type-guards.ts"},{"path":"/zh/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/zh/play/typescript/language-extensions/enums.ts"},{"path":"/zh/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/zh/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/zh/play/typescript/meta-types/conditional-types.ts"},{"path":"/zh/play/typescript/meta-types/discriminate-types.ts"},{"path":"/zh/play/typescript/meta-types/indexed-types.ts"},{"path":"/zh/play/typescript/meta-types/mapped-types.ts"},{"path":"/zh/play/typescript/primitives/any.ts"},{"path":"/zh/play/typescript/primitives/literals.ts"},{"path":"/zh/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/zh/play/typescript/primitives/unknown-and-never.ts"},{"path":"/zh/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/zh/play/typescript/type-primitives/nullable-types.ts"},{"path":"/zh/play/typescript/type-primitives/tuples.ts"},{"path":"/zh/play/javascript/modern-javascript/immutability.ts"},{"path":"/zh/play/javascript/modern-javascript/async-await.ts"},{"path":"/zh/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/community"},{"path":"/es/community"},{"path":"/ja/community"},{"path":"/vo/community"},{"path":"/zh/community"},{"path":"/download"},{"path":"/es/download"},{"path":"/ja/download"},{"path":"/vo/download"},{"path":"/zh/download"},{"path":"/empty"},{"path":"/es/empty"},{"path":"/ja/empty"},{"path":"/vo/empty"},{"path":"/zh/empty"},{"path":"/"},{"path":"/es/"},{"path":"/ja/"},{"path":"/vo/"},{"path":"/zh/"},{"path":"/tools"},{"path":"/es/tools"},{"path":"/ja/tools"},{"path":"/vo/tools"},{"path":"/zh/tools"},{"path":"/why-create-typescript"},{"path":"/es/why-create-typescript"},{"path":"/ja/why-create-typescript"},{"path":"/vo/why-create-typescript"},{"path":"/zh/why-create-typescript"},{"path":"/docs/home"},{"path":"/es/docs/home"},{"path":"/ja/docs/home"},{"path":"/vo/docs/home"},{"path":"/zh/docs/home"},{"path":"/dev/playground-plugins/"},{"path":"/dev/sandbox/"},{"path":"/dev/twoslash/"},{"path":"/dev/typescript-vfs/"}]},"markdownRemark":{"id":"be1ed457-3aef-5ae7-a0a2-66a46df8a18d","excerpt":"This quick start guide will teach you how to build TypeScript with gulp and then add Browserify, uglify, or Watchify to the gulp pipeline.\nThis guide also shows…","html":"<p>This quick start guide will teach you how to build TypeScript with <a href=\"http://gulpjs.com\">gulp</a> and then add <a href=\"http://browserify.org\">Browserify</a>, <a href=\"http://lisperator.net/uglifyjs/\">uglify</a>, or <a href=\"https://github.com/substack/watchify\">Watchify</a> to the gulp pipeline.\nThis guide also shows how to add <a href=\"https://babeljs.io/\">Babel</a> functionality using <a href=\"https://github.com/babel/babelify\">Babelify</a>.</p>\n<p>We assume that you’re already using <a href=\"https://nodejs.org/\">Node.js</a> with <a href=\"https://www.npmjs.com/\">npm</a>.</p>\n<h1 id=\"minimal-project\" style=\"position:relative;\"><a href=\"#minimal-project\" aria-label=\"minimal project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Minimal project</h1>\n<p>Let’s start out with a new directory.\nWe’ll name it <code>proj</code> for now, but you can change it to whatever you want.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">mkdir proj</span>\n<span style=\"color: #000000\">cd proj</span></code></div></pre>\n<p>To start, we’re going to structure our project in the following way:</p>\n<pre><code>proj/\n   ├─ src/\n   └─ dist/\n</code></pre>\n<p>TypeScript files will start out in your <code>src</code> folder, run through the TypeScript compiler and end up in <code>dist</code>.</p>\n<p>Let’s scaffold this out:</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">mkdir src</span>\n<span style=\"color: #000000\">mkdir dist</span></code></div></pre>\n<h2 id=\"initialize-the-project\" style=\"position:relative;\"><a href=\"#initialize-the-project\" aria-label=\"initialize the project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initialize the project</h2>\n<p>Now we’ll turn this folder into an npm package.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm init</span></code></div></pre>\n<p>You’ll be given a series of prompts.\nYou can use the defaults except for your entry point.\nFor your entry point, use <code>./dist/main.js</code>.\nYou can always go back and change these in the <code>package.json</code> file that’s been generated for you.</p>\n<h2 id=\"install-our-dependencies\" style=\"position:relative;\"><a href=\"#install-our-dependencies\" aria-label=\"install our dependencies permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Install our dependencies</h2>\n<p>Now we can use <code>npm install</code> to install packages.\nFirst install <code>gulp-cli</code> globally (if you use a Unix system, you may need to prefix the <code>npm install</code> commands in this guide with <code>sudo</code>).</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install -g gulp-cli</span></code></div></pre>\n<p>Then install <code>typescript</code>, <code>gulp</code> and <code>gulp-typescript</code> in your project’s dev dependencies.\n<a href=\"https://www.npmjs.com/package/gulp-typescript\">Gulp-typescript</a> is a gulp plugin for Typescript.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save-dev typescript gulp@4.0.0 gulp-typescript</span></code></div></pre>\n<h2 id=\"write-a-simple-example\" style=\"position:relative;\"><a href=\"#write-a-simple-example\" aria-label=\"write a simple example permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Write a simple example</h2>\n<p>Let’s write a Hello World program.\nIn <code>src</code>, create the file <code>main.ts</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> hello(compiler: string) {</span>\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #A31515\">`Hello from </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\">compiler</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">`</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #000000\">hello(</span><span style=\"color: #A31515\">'TypeScript'</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>In the project root, <code>proj</code>, create the file <code>tsconfig.json</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"files\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"src/main.ts\"</span>\n<span style=\"color: #000000\">    ],</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"noImplicitAny\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"target\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"es5\"</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"create-a-gulpfilejs\" style=\"position:relative;\"><a href=\"#create-a-gulpfilejs\" aria-label=\"create a gulpfilejs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a <code>gulpfile.js</code></h2>\n<p>In the project root, create the file <code>gulpfile.js</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> gulp = require(</span><span style=\"color: #A31515\">'gulp'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> ts = require(</span><span style=\"color: #A31515\">'gulp-typescript'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tsProject = ts.createProject(</span><span style=\"color: #A31515\">'tsconfig.json'</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> tsProject.src()</span>\n<span style=\"color: #000000\">        .pipe(tsProject())</span>\n<span style=\"color: #000000\">        .js.pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">});</span></code></div></pre>\n<h2 id=\"test-the-resulting-app\" style=\"position:relative;\"><a href=\"#test-the-resulting-app\" aria-label=\"test the resulting app permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Test the resulting app</h2>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">gulp</span>\n<span style=\"color: #000000\">node dist/main.js</span></code></div></pre>\n<p>The program should print “Hello from TypeScript!“.</p>\n<h1 id=\"add-modules-to-the-code\" style=\"position:relative;\"><a href=\"#add-modules-to-the-code\" aria-label=\"add modules to the code permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Add modules to the code</h1>\n<p>Before we get to Browserify, let’s build our code out and add modules to the mix.\nThis is the structure you’re more likely to use for a real app.</p>\n<p>Create a file called <code>src/greet.ts</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">export</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> sayHello(name: string) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">`Hello from </span><span style=\"color: #0000FF\">${</span><span style=\"color: #A31515\">name</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">`</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Now change the code in <code>src/main.ts</code> to import <code>sayHello</code> from <code>greet.ts</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { sayHello } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'./greet'</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #000000\">console.log(sayHello(</span><span style=\"color: #A31515\">'TypeScript'</span><span style=\"color: #000000\">));</span></code></div></pre>\n<p>Finally, add <code>src/greet.ts</code> to <code>tsconfig.json</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"files\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"src/main.ts\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"src/greet.ts\"</span>\n<span style=\"color: #000000\">    ],</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"noImplicitAny\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"target\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"es5\"</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Make sure that the modules work by running <code>gulp</code> and then testing in Node:</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">gulp</span>\n<span style=\"color: #000000\">node dist/main.js</span></code></div></pre>\n<p>Notice that even though we used ES2015 module syntax, TypeScript emitted CommonJS modules that Node uses.\nWe’ll stick with CommonJS for this tutorial, but you could set <code>module</code> in the options object to change this.</p>\n<h1 id=\"browserify\" style=\"position:relative;\"><a href=\"#browserify\" aria-label=\"browserify permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Browserify</h1>\n<p>Now let’s move this project from Node to the browser.\nTo do this, we’d  like to bundle all our modules into one JavaScript file.\nFortunately, that’s exactly what Browserify does.\nEven better, it lets us use the CommonJS module system used by Node, which is the default TypeScript emit.\nThat means our TypeScript and Node setup will transfer to the browser basically unchanged.</p>\n<p>First, install browserify, <a href=\"https://www.npmjs.com/package/tsify\">tsify</a>, and vinyl-source-stream.\ntsify is a Browserify plugin that, like gulp-typescript, gives access to the TypeScript compiler.\nvinyl-source-stream lets us adapt the file output of Browserify back into a format that gulp understands called <a href=\"https://github.com/gulpjs/vinyl\">vinyl</a>.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save-dev browserify tsify vinyl-source-stream</span></code></div></pre>\n<h2 id=\"create-a-page\" style=\"position:relative;\"><a href=\"#create-a-page\" aria-label=\"create a page permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a page</h2>\n<p>Create a file in <code>src</code> named <code>index.html</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">html</div><div class='code-container'><code><span style=\"color: #800000\">&lt;!</span><span style=\"color: #000000\">DOCTYPE html</span><span style=\"color: #800000\">&gt;</span>\n<span style=\"color: #800000\">&lt;html&gt;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #800000\">&lt;head&gt;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #800000\">&lt;meta</span><span style=\"color: #000000\"> </span><span style=\"color: #DC0000\">charset</span><span style=\"color: #000000\">=</span><span style=\"color: #0000FF\">\"UTF-8\"</span><span style=\"color: #800000\"> /&gt;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #800000\">&lt;title&gt;</span><span style=\"color: #000000\">Hello World!</span><span style=\"color: #800000\">&lt;/title&gt;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #800000\">&lt;/head&gt;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #800000\">&lt;body&gt;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #800000\">&lt;p</span><span style=\"color: #000000\"> </span><span style=\"color: #DC0000\">id</span><span style=\"color: #000000\">=</span><span style=\"color: #0000FF\">\"greeting\"</span><span style=\"color: #800000\">&gt;</span><span style=\"color: #000000\">Loading ...</span><span style=\"color: #800000\">&lt;/p&gt;</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #800000\">&lt;script</span><span style=\"color: #000000\"> </span><span style=\"color: #DC0000\">src</span><span style=\"color: #000000\">=</span><span style=\"color: #0000FF\">\"bundle.js\"</span><span style=\"color: #800000\">&gt;&lt;/script&gt;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #800000\">&lt;/body&gt;</span>\n<span style=\"color: #800000\">&lt;/html&gt;</span></code></div></pre>\n<p>Now change <code>main.ts</code> to update the page:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">import</span><span style=\"color: #000000\"> { sayHello } </span><span style=\"color: #0000FF\">from</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">'./greet'</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> showHello(divName: string, name: string) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> elt = document.getElementById(divName);</span>\n<span style=\"color: #000000\">    elt.innerText = sayHello(name);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">showHello(</span><span style=\"color: #A31515\">'greeting'</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">'TypeScript'</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>Calling <code>showHello</code> calls <code>sayHello</code> to change the paragraph’s text.\nNow change your gulpfile to the following:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> gulp = require(</span><span style=\"color: #A31515\">'gulp'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> browserify = require(</span><span style=\"color: #A31515\">'browserify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> source = require(</span><span style=\"color: #A31515\">'vinyl-source-stream'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tsify = require(</span><span style=\"color: #A31515\">'tsify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> paths = {</span>\n<span style=\"color: #000000\">    pages: [</span><span style=\"color: #A31515\">'src/*.html'</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> gulp.src(paths.pages)</span>\n<span style=\"color: #000000\">        .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">, gulp.series(gulp.parallel(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">), </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> browserify({</span>\n<span style=\"color: #000000\">        basedir: </span><span style=\"color: #A31515\">'.'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        debug: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        entries: [</span><span style=\"color: #A31515\">'src/main.ts'</span><span style=\"color: #000000\">],</span>\n<span style=\"color: #000000\">        cache: {},</span>\n<span style=\"color: #000000\">        packageCache: {}</span>\n<span style=\"color: #000000\">    })</span>\n<span style=\"color: #000000\">    .plugin(tsify)</span>\n<span style=\"color: #000000\">    .bundle()</span>\n<span style=\"color: #000000\">    .pipe(source(</span><span style=\"color: #A31515\">'bundle.js'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">    .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">}));</span></code></div></pre>\n<p>This adds the <code>copy-html</code> task and adds it as a dependency of <code>default</code>.\nThat means any time <code>default</code> is run, <code>copy-html</code> has to run first.\nWe’ve also changed <code>default</code> to call Browserify with the tsify plugin instead of gulp-typescript.\nConveniently, they both allow us to pass the same options object to the TypeScript compiler.</p>\n<p>After calling <code>bundle</code> we use <code>source</code> (our alias for vinyl-source-stream) to name our output bundle <code>bundle.js</code>.</p>\n<p>Test the page by running gulp and then opening <code>dist/index.html</code> in a browser.\nYou should see “Hello from TypeScript” on the page.</p>\n<p>Notice that we specified <code>debug: true</code> to Browserify.\nThis causes tsify to emit source maps inside the bundled JavaScript file.\nSource maps let you debug your original TypeScript code in the browser instead of the bundled JavaScript.\nYou can test that source maps are working by opening the debugger for your browser and putting a breakpoint inside <code>main.ts</code>.\nWhen you refresh the page the breakpoint should pause the page and let you debug <code>greet.ts</code>.</p>\n<h1 id=\"watchify-babel-and-uglify\" style=\"position:relative;\"><a href=\"#watchify-babel-and-uglify\" aria-label=\"watchify babel and uglify permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Watchify, Babel, and Uglify</h1>\n<p>Now that we are bundling our code with Browserify and tsify, we can add various features to our build with browserify plugins.</p>\n<ul>\n<li>Watchify starts gulp and keeps it running, incrementally compiling whenever you save a file.\nThis lets you keep an edit-save-refresh cycle going in the browser.</li>\n<li>Babel is a hugely flexible compiler that converts ES2015 and beyond into ES5 and ES3.\nThis lets you add extensive and customized transformations that TypeScript doesn’t support.</li>\n<li>Uglify compacts your code so that it takes less time to download.</li>\n</ul>\n<h2 id=\"watchify\" style=\"position:relative;\"><a href=\"#watchify\" aria-label=\"watchify permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Watchify</h2>\n<p>We’ll start with Watchify to provide background compilation:</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save-dev watchify fancy-log</span></code></div></pre>\n<p>Now change your gulpfile to the following:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> gulp = require(</span><span style=\"color: #A31515\">'gulp'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> browserify = require(</span><span style=\"color: #A31515\">'browserify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> source = require(</span><span style=\"color: #A31515\">'vinyl-source-stream'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> watchify = require(</span><span style=\"color: #A31515\">'watchify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tsify = require(</span><span style=\"color: #A31515\">'tsify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> fancy_log = require(</span><span style=\"color: #A31515\">'fancy-log'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> paths = {</span>\n<span style=\"color: #000000\">    pages: [</span><span style=\"color: #A31515\">'src/*.html'</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> watchedBrowserify = watchify(browserify({</span>\n<span style=\"color: #000000\">    basedir: </span><span style=\"color: #A31515\">'.'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    debug: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    entries: [</span><span style=\"color: #A31515\">'src/main.ts'</span><span style=\"color: #000000\">],</span>\n<span style=\"color: #000000\">    cache: {},</span>\n<span style=\"color: #000000\">    packageCache: {}</span>\n<span style=\"color: #000000\">}).plugin(tsify));</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> gulp.src(paths.pages)</span>\n<span style=\"color: #000000\">        .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> bundle() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> watchedBrowserify</span>\n<span style=\"color: #000000\">        .bundle()</span>\n<span style=\"color: #000000\">        .on(</span><span style=\"color: #A31515\">'error'</span><span style=\"color: #000000\">, fancy_log)</span>\n<span style=\"color: #000000\">        .pipe(source(</span><span style=\"color: #A31515\">'bundle.js'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">        .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">, gulp.series(gulp.parallel(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">), bundle));</span>\n<span style=\"color: #000000\">watchedBrowserify.on(</span><span style=\"color: #A31515\">'update'</span><span style=\"color: #000000\">, bundle);</span>\n<span style=\"color: #000000\">watchedBrowserify.on(</span><span style=\"color: #A31515\">'log'</span><span style=\"color: #000000\">, fancy_log);</span></code></div></pre>\n<p>There are basically three changes here, but they require you to refactor your code a bit.</p>\n<ol>\n<li>We wrapped our <code>browserify</code> instance in a call to <code>watchify</code>, and then held on to the result.</li>\n<li>We called <code>watchedBrowserify.on('update', bundle);</code> so that Browserify will run the <code>bundle</code> function every time one of your TypeScript files changes.</li>\n<li>We called <code>watchedBrowserify.on('log', fancy_log);</code> to log to the console.</li>\n</ol>\n<p>Together (1) and (2) mean that we have to move our call to <code>browserify</code> out of the <code>default</code> task.\nAnd we have to give the function for <code>default</code> a name since both Watchify and Gulp need to call it.\nAdding logging with (3) is optional but very useful for debugging your setup.</p>\n<p>Now when you run Gulp, it should start and stay running.\nTry changing the code for <code>showHello</code> in <code>main.ts</code> and saving it.\nYou should see output that looks like this:</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">proj$ gulp</span>\n<span style=\"color: #000000\">[10:34:20] Using gulpfile ~/src/proj/gulpfile.js</span>\n<span style=\"color: #000000\">[10:34:20] Starting </span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">...</span>\n<span style=\"color: #000000\">[10:34:20] Finished </span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\"> after 26 ms</span>\n<span style=\"color: #000000\">[10:34:20] Starting </span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">...</span>\n<span style=\"color: #000000\">[10:34:21] 2824 bytes written (0.13 seconds)</span>\n<span style=\"color: #000000\">[10:34:21] Finished </span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\"> after 1.36 s</span>\n<span style=\"color: #000000\">[10:35:22] 2261 bytes written (0.02 seconds)</span>\n<span style=\"color: #000000\">[10:35:24] 2808 bytes written (0.05 seconds)</span></code></div></pre>\n<h2 id=\"uglify\" style=\"position:relative;\"><a href=\"#uglify\" aria-label=\"uglify permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Uglify</h2>\n<p>First install Uglify.\nSince the point of Uglify is to mangle your code, we also need to install vinyl-buffer and gulp-sourcemaps to keep sourcemaps working.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save-dev gulp-uglify vinyl-buffer gulp-sourcemaps</span></code></div></pre>\n<p>Now change your gulpfile to the following:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> gulp = require(</span><span style=\"color: #A31515\">'gulp'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> browserify = require(</span><span style=\"color: #A31515\">'browserify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> source = require(</span><span style=\"color: #A31515\">'vinyl-source-stream'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tsify = require(</span><span style=\"color: #A31515\">'tsify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> uglify = require(</span><span style=\"color: #A31515\">'gulp-uglify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sourcemaps = require(</span><span style=\"color: #A31515\">'gulp-sourcemaps'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> buffer = require(</span><span style=\"color: #A31515\">'vinyl-buffer'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> paths = {</span>\n<span style=\"color: #000000\">    pages: [</span><span style=\"color: #A31515\">'src/*.html'</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> gulp.src(paths.pages)</span>\n<span style=\"color: #000000\">        .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">, gulp.series(gulp.parallel(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">), </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> browserify({</span>\n<span style=\"color: #000000\">        basedir: </span><span style=\"color: #A31515\">'.'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        debug: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        entries: [</span><span style=\"color: #A31515\">'src/main.ts'</span><span style=\"color: #000000\">],</span>\n<span style=\"color: #000000\">        cache: {},</span>\n<span style=\"color: #000000\">        packageCache: {}</span>\n<span style=\"color: #000000\">    })</span>\n<span style=\"color: #000000\">    .plugin(tsify)</span>\n<span style=\"color: #000000\">    .bundle()</span>\n<span style=\"color: #000000\">    .pipe(source(</span><span style=\"color: #A31515\">'bundle.js'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">    .pipe(buffer())</span>\n<span style=\"color: #000000\">    .pipe(sourcemaps.init({loadMaps: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">}))</span>\n<span style=\"color: #000000\">    .pipe(uglify())</span>\n<span style=\"color: #000000\">    .pipe(sourcemaps.write(</span><span style=\"color: #A31515\">'./'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">    .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">}));</span></code></div></pre>\n<p>Notice that <code>uglify</code> itself has just one call — the calls to <code>buffer</code> and <code>sourcemaps</code> exist to make sure sourcemaps keep working.\nThese calls give us a separate sourcemap file instead of using inline sourcemaps like before.\nNow you can run Gulp and check that <code>bundle.js</code> does get minified into an unreadable mess:</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">gulp</span>\n<span style=\"color: #000000\">cat dist/bundle.js</span></code></div></pre>\n<h2 id=\"babel\" style=\"position:relative;\"><a href=\"#babel\" aria-label=\"babel permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Babel</h2>\n<p>First install Babelify and the Babel preset for ES2015.\nLike Uglify, Babelify mangles code, so we’ll need vinyl-buffer and gulp-sourcemaps.\nBy default Babelify will only process files with extensions of <code>.js</code>, <code>.es</code>, <code>.es6</code> and <code>.jsx</code> so we need to add the <code>.ts</code> extension as an option to Babelify.</p>\n<pre class=\"shiki\"><div class=\"language-id\">shell</div><div class='code-container'><code><span style=\"color: #000000\">npm install --save-dev babelify@8 babel-core babel-preset-es2015 vinyl-buffer gulp-sourcemaps</span></code></div></pre>\n<p>Now change your gulpfile to the following:</p>\n<pre class=\"shiki\"><div class=\"language-id\">js</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> gulp = require(</span><span style=\"color: #A31515\">'gulp'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> browserify = require(</span><span style=\"color: #A31515\">'browserify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> source = require(</span><span style=\"color: #A31515\">'vinyl-source-stream'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> tsify = require(</span><span style=\"color: #A31515\">'tsify'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> sourcemaps = require(</span><span style=\"color: #A31515\">'gulp-sourcemaps'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> buffer = require(</span><span style=\"color: #A31515\">'vinyl-buffer'</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> paths = {</span>\n<span style=\"color: #000000\">    pages: [</span><span style=\"color: #A31515\">'src/*.html'</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">, </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> gulp.src(paths.pages)</span>\n<span style=\"color: #000000\">        .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #000000\">gulp.task(</span><span style=\"color: #A31515\">'default'</span><span style=\"color: #000000\">, gulp.series(gulp.parallel(</span><span style=\"color: #A31515\">'copy-html'</span><span style=\"color: #000000\">), </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> () {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> browserify({</span>\n<span style=\"color: #000000\">        basedir: </span><span style=\"color: #A31515\">'.'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        debug: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        entries: [</span><span style=\"color: #A31515\">'src/main.ts'</span><span style=\"color: #000000\">],</span>\n<span style=\"color: #000000\">        cache: {},</span>\n<span style=\"color: #000000\">        packageCache: {}</span>\n<span style=\"color: #000000\">    })</span>\n<span style=\"color: #000000\">    .plugin(tsify)</span>\n<span style=\"color: #000000\">    .transform(</span><span style=\"color: #A31515\">'babelify'</span><span style=\"color: #000000\">, {</span>\n<span style=\"color: #000000\">        presets: [</span><span style=\"color: #A31515\">'es2015'</span><span style=\"color: #000000\">],</span>\n<span style=\"color: #000000\">        extensions: [</span><span style=\"color: #A31515\">'.ts'</span><span style=\"color: #000000\">]</span>\n<span style=\"color: #000000\">    })</span>\n<span style=\"color: #000000\">    .bundle()</span>\n<span style=\"color: #000000\">    .pipe(source(</span><span style=\"color: #A31515\">'bundle.js'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">    .pipe(buffer())</span>\n<span style=\"color: #000000\">    .pipe(sourcemaps.init({loadMaps: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">}))</span>\n<span style=\"color: #000000\">    .pipe(sourcemaps.write(</span><span style=\"color: #A31515\">'./'</span><span style=\"color: #000000\">))</span>\n<span style=\"color: #000000\">    .pipe(gulp.dest(</span><span style=\"color: #A31515\">'dist'</span><span style=\"color: #000000\">));</span>\n<span style=\"color: #000000\">}));</span></code></div></pre>\n<p>We also need to have TypeScript target ES2015.\nBabel will then produce ES5 from the ES2015 code that TypeScript emits.\nLet’s modify <code>tsconfig.json</code>:</p>\n<pre class=\"shiki\"><div class=\"language-id\">json</div><div class='code-container'><code><span style=\"color: #000000\">{</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"files\"</span><span style=\"color: #000000\">: [</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #A31515\">\"src/main.ts\"</span>\n<span style=\"color: #000000\">    ],</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0451A5\">\"compilerOptions\"</span><span style=\"color: #000000\">: {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"noImplicitAny\"</span><span style=\"color: #000000\">: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0451A5\">\"target\"</span><span style=\"color: #000000\">: </span><span style=\"color: #A31515\">\"es2015\"</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>Babel’s ES5 output should be very similar to TypeScript’s output for such a simple script.</p>","headings":[{"value":"Minimal project","depth":1},{"value":"Initialize the project","depth":2},{"value":"Install our dependencies","depth":2},{"value":"Write a simple example","depth":2},{"value":"Create a gulpfile.js","depth":2},{"value":"Test the resulting app","depth":2},{"value":"Add modules to the code","depth":1},{"value":"Browserify","depth":1},{"value":"Create a page","depth":2},{"value":"Watchify, Babel, and Uglify","depth":1},{"value":"Watchify","depth":2},{"value":"Uglify","depth":2},{"value":"Babel","depth":2}],"frontmatter":{"permalink":"/docs/handbook/gulp.html","title":"Gulp"}}},"pageContext":{"slug":"/docs/handbook/gulp.html","isOldHandbook":true}}}