2

从 Typescript 2.0.10 升级到 2.1.4 似乎破坏了 webpack、webpack-stream、ts-loader 或 gulp 中的某些内容,因为它不再尊重我的入口点或 gulp 源 glob。它似乎包括我的项目中的所有 .ts 文件(包括 /server 源文件夹中的文件),而不仅仅是 /client 和 app.ts 中的 ts 文件,根据 gulp.src 和 web pack 入口点。我应该这样做有不同/更新/更好的方式吗?

在 gulp 文件中:

const serverPath = 'server';
const clientPath = 'client';
const buildPath = 'build';
const paths = {
    server: {
        scripts: [
            `${serverPath}/**/*.ts`
        ]
    },
    client: {
        files: [
            `${clientPath}/**/*`
        ],
        scripts: [
            `${clientPath}/**/*.ts`
        ],
        entry: `${clientPath}/app.ts`
    }
};


gulp.task('build:client', cb => {
    gulp.src(paths.client.entry)
        .pipe(webpackStream(webpackConfig, webpack))
        .pipe(gulp.dest(`${buildPath}/${clientPath}`));
    cb();
});

在 web 包配置中:

entry: {
    app: './client/app.ts'
}

ts: {
    configFileName: './tsconfig.json'
}

resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
}

module: {
    loaders: [
        { test: /\.ts$/, loader: 'ng-annotate-loader!ts-loader' }
    ]
}

在 tsconfig.json 中:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "removeComments": false,
        "noImplicitAny": true,
        "sourceMap": true,
        "inlineSources": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}

使用 2.0.10 输出:

ts-loader: Using typescript@2.0.10 and /Users/chris/code/class-app/tsconfig.json
[20:47:36] Version: webpack 1.14.0
Asset       Size  Chunks             Chunk Names
app.js.map  950 bytes       0  [emitted]  app
app.js  550 bytes       0  [emitted]  app

使用 2.1.4 输出:

ts-loader: Using typescript@2.1.4 and /Users/chris/code/class-app/tsconfig.json
server/api/thing/thing.controller.ts(17,16): error TS2322: <ts error in server portion, not relevant>
[20:53:03] TypeScript: 1 semantic error
[20:53:03] TypeScript: emit succeeded (with errors)
Unhandled rejection Error in plugin 'webpack-stream'
Message:
/Users/chris/code/class-app/server/api/thing/thing.controller.ts <same as above>
4

1 回答 1

2

显然问题是 WebPack 中的 TypeScript 一直在服务器代码上运行(尽管它不应该一直运行),虽然我计划修复升级 TypeScript 引入的服务器 TS 问题,但它真正暴露的是 WebPack 正在编译它不应该一直拥有的文件。通过故意在先前(“工作”)版本的 TypeScript 上向服务器 ts 引入问题来测试这一点,得到相同的错误。

我仍然需要弄清楚它为什么要编译我所有的 TS 文件,而不仅仅是 /client 中的那些,但我会为此提出一个新问题。

于 2016-12-22T17:59:50.333 回答