Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • TypeScript - Get Started
  • TypeScript - Overview
  • TypeScript - Installation
  • TypeScript - First Program
  • TypeScript - Type Annotation
  • TypeScript - Variable
  • Data Types - Number
  • String
  • Boolean
  • Array
  • Tuple
  • Enum
  • Union
  • Any
  • Void
  • Never
  • Type Inference
  • Type Assertion
  • if Statement
  • switch Statement
  • for Loop
  • while Loop
  • Function
  • Arrow Function
  • Function Overloading
  • Rest Parameters
  • Interface
  • Class
  • Abstract Class
  • Data Modifiers
  • ReadOnly
  • Static
  • Module
  • Compiling a Module
  • Namespace
  • Generic
  • Generic Interface
  • Generic Class
  • Compiling Project
  • Build Tools
  • Convert JavaScript to TypeScript
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

TypeScript - Build Tools

Build Tools are utilities that help automate the transformation and bundling of your code into a single file. Most JavaScript projects use these build tools to automate the build process.

There are several common build tools available that can be integrated with TypeScript. We will take a look at how to integrate TypeScript with some of these tools:

  • Browserify
  • Grunt
  • Gulp
  • Webpack

Browserify

Use Browserify plugin Tsify for compiling TypeScript files.

Install Tsify using NPM (Node.js Package Manager) using the following command:

npm install tsify

Use the following command to compile your code and output the result in a file named bundle.js.

browserify main.ts -p [ tsify --noImplicitAny ] > bundle.js

Grunt

Use grunt-ts plugin from Grunt for TypeScript.

Install Grunt-ts using the following NPM command:

npm install grunt-ts

You will need to include the Grunt config file:

module.exports = function(grunt) {
    grunt.initConfig({
        ts: {
                default : {
                src: ["**/*.ts", "!node_modules/**/*.ts"]
            }
        }
    });
    grunt.loadNpmTasks("grunt-ts");
    grunt.registerTask("default", ["ts"]);
};

Gulp

Use gulp-typescript plugin for TypeScript.

Install it using the following NPM command:

npm install gulp-typescript

You will need to include the gulp config file:

var gulp = require("gulp");
var ts = require("gulp-typescript");

gulp.task("default", function () {
                var tsResult = gulp.src("src/*.ts")
        .pipe(ts({
              noImplicitAny: true,
                out: "output.js"
        }));
                return tsResult.js.pipe(gulp.dest("built/local"));
});

Webpack

Use ts-loader plugin for TypeScript.

npm install ts-loader –save-dev

OR

npm install awesome-typescript-loader

You will need to include the webpack.config.js config file:

module.exports = {
    entry: "./src/index.tsx",
    output: {
        filename: "bundle.js"
    },
    resolve: {
                // Add '.ts' and '.tsx' as a resolvable extension.
        extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    module: {
        loaders: [
                // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'
            { test: /.tsx?$/, loader: "ts-loader" } // replace with your plugin of choice
        ]
    }
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.