【问题标题】:Exclude third party libraries from typescript build从打字稿构建中排除第三方库
【发布时间】:2018-01-06 21:24:35
【问题描述】:

我想从我的结果包中排除导入的库。 假设我们有下一个代码:

import * as angular from 'angular';
const app = angular.module('app',[]);

我们有这个构建任务。

function buildTs(compileOptions) {
    browserify(compileOptions)
        .plugin(tsify, tsconfig.compileOptions)
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(gulp.dest(path.dest.js));
}

构建完成后,Angular 库将包含在 bundle.js 中。 我可以避免这种情况吗?

我的 tsConfig:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": true,
    "sourceMap": true,
    "types": [
      "angular",
      "angular-cookies",
      "angular-ui-bootstrap",
      "angular-ui-router",
      "jasmine",
      "angular-mocks"
    ]
  },
  "include": [
    "app"
  ],
  "exclude": [
    "node_modules"
  ]
}

从类型中删除类型没有帮助:)

【问题讨论】:

  • 您好,angularangularjs 标签不同。我要求请删除任何一个不必要的标签。标签 angular 用于 Angular 2/4(严格),angularjs 用于 Angular 1.x。谢谢

标签: angularjs typescript gulp


【解决方案1】:

这将使 browserify 忽略 angularjs ,然后可以从 index.html 中添加。

var browserify = require("browserify")

browserify()
.ignore('angular')

是否可以包含多个文件而不每次都添加.ignore(name)?像这样使用数组或smth?

var tsProject = ts.createProject('tsconfig.json');
gulp.task('scripts', function() { 
    var tsResult = gulp.src("lib/**/*.ts") 

    // or 
    tsProject.src() 
      .pipe(tsProject()); 

    return tsResult.js.pipe(gulp.dest('release'));
});

因此,这可能是构建 Typescript 文件的一种更简洁的方式。在 src 中,您可以提供自己的正则表达式 src 文件列表。

【讨论】:

  • 似乎工作。有什么选项可以包含多个文件而不每次都添加 .ignore(name) 吗?像这样使用数组或smth?
  • var tsProject = ts.createProject('tsconfig.json'); gulp.task('scripts', function() { var tsResult = gulp.src("lib/**/*.ts") // or tsProject.src() .pipe(tsProject()); return tsResult.js .pipe(gulp.dest('release')); }); _____________________________________ 因此,这可能是构建 Typescript 文件的一种更简洁的方式。在 src 中,您可以提供自己的正则表达式 src 文件列表。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-18
  • 2015-11-25
  • 1970-01-01
  • 1970-01-01
  • 2019-03-17
相关资源
最近更新 更多