TypeScript 2.1.4突破了webpack ts-loader的变化 [英] TypeScript 2.1.4 breaking changes in webpack ts-loader

查看:731
本文介绍了TypeScript 2.1.4突破了webpack ts-loader的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Upgrading from Typescript 2.0.10 to 2.1.4 appears to break something in webpack, webpack-stream, ts-loader, or gulp as it’s no longer respecting my entry point or gulp source glob. It appears to be including all .ts files in my project (including the ones in the /server source folder) rather than just the ts files in /client and app.ts as per the gulp.src and web pack entry point. Is there a different/newer/better way I should be doing this?

in gulp file:

in gulp file:

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

在网页包配置中:

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中:

in tsconfig.json:

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

使用2.0.10输出:

Output using 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的输出:

Output using 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>


推荐答案

显然问题是WebPack中的TypeScript已经运行整个服务器代码都是这样的(尽管它不应该是这样),虽然我已经计划修复升级TypeScript引入的服务器TS问题,但它确实暴露的是WebPack正在编译它不应该一直存在的文件。通过在TypeScript的前一个(工作)版本上向服务器ts故意引入一个问题,得到相同的错误,对此进行了测试。

Apparently the problem is TypeScript in WebPack has been running on the server code this whole time (although it shouldn't have been) and although I had planned to fix the server TS issue that upgrading TypeScript introduced, what it really exposed was WebPack was compiling files it shouldn't have all along. Tested this by intentionally introducing a problem to the server ts on the previous ("working") version of TypeScript, getting the same error.

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

I still need to figure out why it's trying to compile all my TS files, and not just the ones in /client, but I'll ask a new question for that.

这篇关于TypeScript 2.1.4突破了webpack ts-loader的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆