Skip to content

feat: translate Integrating with Build Tools.md in zh-CN #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EnochGao
Copy link

translate Integrating with Build Tools.md in zh-CN

@github-actions
Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @Kingwl - if they write a comment saying "LGTM" then it will be merged.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2022

Translation of Integrating with Build Tools.md

title: Integrates with build tools
layout: docs
permalink: /zh/docs/handbook/integrating-with-build-tools.html
oneline: How to use TypeScript with other build tools

translatable: true

Babel

Installation

npm install @babel/cli @babel/core @babel/preset-typescript --save-dev

.babelrc

{
  "presets": ["@babel/preset-typescript"]
}

Command line execution

./node_modules/.bin/babel --out-file bundle.js src/index.ts

package.json

{
  "scripts": {
    "build": "babel --out-file bundle.js main.ts"
  },
}

Execute Babel from the command line

npm run build

Browserify

Installation

npm install tsify

Command line execution

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

Use the 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

Grunt

Installation

npm install grunt-ts

Base Gruntfile .js

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

More details: TypeStrong/grunt-ts

Gulp

Installation

npm install gulp-typescript

Base gulpfile .js

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"));
});

More details: ivogabe/gulp-typescript

Jspm

Installation

npm install -g jspm@beta

Note: TypeScript is currently supported in version 0.16beta of jspm

More details: TypeScriptSamples/jspm

MSBuild

Update the project files, including those installed locallyMicrosoft.TypeScript.Default.props (top) and Microsoft.TypeScript.targets (bottom) file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Include default props at the top -->
  <Import
      Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props"
      Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

  <!-- TypeScript configurations go here -->
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>

  <!-- Include default targets at the bottom -->
  <Import
      Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
      Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
</Project>

More details about defining MSBuild compiler options: Set compiler options in the MSBuild project

NuGet

  • Right-click -> Manage NuGet Packages
  • Search Microsoft.TypeScript.MSBuild
  • click Install
  • Rebuild after installation!

More details can be viewed Package Manager Dialog and using nightly builds with NuGet

Rollup

Installation

npm install @rollup/plugin-typescript --save-dev

Please note thattypescriptandtslibare peer dependencies of this plugin and need to be installed separately.

use

Create one rollup.config.js Configuration file And import the plugin:

// rollup.config.js
import typescript from '@rollup/plugin-typescript';

export default {
  input: 'src/index.ts',
  output: {
    dir: 'output',
    format: 'cjs'
  },
  plugins: [typescript()]
};

Svelte Compiler

Installation

npm install --save-dev svelte-preprocess

Please note thattypescript is the peerDependencies for this plugin and needs to be installed separately. tslib Also not provided.

You can also consider using svelte-check Do CLI type checking.

use

Create one svelte.config.js Configure the file and import the plugin:

// svelte.config.js
import preprocess from 'svelte-preprocess';

const config = {
  // Consult https://github.com/sveltejs/svelte-preprocess
  // for more information about preprocessors
  preprocess: preprocess()
};

export default config;

Now you can specify that the script block be written in TypeScript:

<script lang="ts">

Vite

Vite supports out-of-the-box imports.tsFile. It only performs transpilation without type checking. It also requirescompilerOptionsSome options in have specific values. For more information, see Vite documentation

Webpack

Installation

npm install ts-loader --save-dev

Basic webpack.config .js when using Webpack version 5 or 4

const path = require('path');

module.exports = {
  entry: './src/index.ts',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

See more ts-loader details here.

Alternatives:

Generated by 🚫 dangerJS against 8589c9c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant