Integrating with Build Tools
Browserify
Section titled “Browserify”Install
Section titled “Install”npm install tsifyUsing Command Line Interface
Section titled “Using Command Line Interface”browserify main.ts -p [ tsify --noImplicitAny ] > bundle.jsUsing API
Section titled “Using API”var browserify = require("browserify");var tsify = require("tsify");
browserify() .add("main.ts") .plugin("tsify", { noImplicitAny: true }) .bundle() .pipe(process.stdout);More details: smrq/tsify
Webpack
Section titled “Webpack”Install
Section titled “Install”npm install ts-loader --save-devBasic webpack.config.js
Section titled “Basic webpack.config.js”webpack 2.x, 3.x
Section titled “webpack 2.x, 3.x”module.exports = { resolve: { extensions: ['.ts', '.tsx', '.js'] }, module: { rules: [ { // Set up ts-loader for .ts/.tsx files and exclude any imports from node_modules. test: /\.tsx?$/, loaders: ['ts-loader'], exclude: /node_modules/ } ] }, entry: [ // Set index.tsx as application entry point. './index.tsx' ], output: { filename: "bundle.js" }};webpack 1.x
Section titled “webpack 1.x”See more details on ts-loader here.
Alternatives:
Install
Section titled “Install”npm install grunt-tsBasic Gruntfile.js
Section titled “Basic Gruntfile.js”More details: TypeStrong/grunt-ts
Install
Section titled “Install”npm install gulp-typescriptBasic gulpfile.js
Section titled “Basic gulpfile.js”gulpfile.js using an existing tsconfig.json
Section titled “gulpfile.js using an existing tsconfig.json”More details: ivogabe/gulp-typescript
MSBuild
Section titled “MSBuild”Update project file to include locally installed Microsoft.TypeScript.Default.props (at the top) and Microsoft.TypeScript.targets (at the bottom) files:
More details about defining MSBuild compiler options: Setting Compiler Options in MSBuild projects
- Right-Click -> Manage NuGet Packages
- Search for
Microsoft.TypeScript.MSBuild - Hit
Install - When install is complete, rebuild!
More details can be found at Package Manager Dialog and using nightly builds with NuGet
Install and configure webpack + loaders
Section titled “Install and configure webpack + loaders”Installation
npm install -D webpack typescript ts-loaderwebpack.config.js
module.exports = { entry: { app: ['./src/'], }, output: { path: __dirname, filename: './dist/[name].js', }, resolve: { extensions: ['', '.js', '.ts'], }, module: { loaders: [{ test: /\.ts(x)$/, loaders: ['ts-loader'], exclude: /node_modules/ }], }};Remarks
Section titled “Remarks”For more information you can go on official web page typescript integrating with build tools