当我只希望WebPack ts-loader在一个文件夹/文件中运行时编译所有文件 [英] WebPack ts-loader compiling all files when I only want it to run in one folder/file

查看:312
本文介绍了当我只希望WebPack ts-loader在一个文件夹/文件中运行时编译所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用WebPack,TypeScript和TS-Loader的应用程序结构和构建过程中发现了一个问题,我认为这是由TypeScript 2.1.4引起的,但显然一直存在.

I found a problem in my app structure and build process using WebPack, TypeScript, and TS-Loader that I thought was caused by TypeScript 2.1.4, but apparently was there the whole time.

您可以从我的其他帖子中看到所有详细信息: TypeScript 2.1.4破坏了webpack ts-loader中的更改

You can see all the details from my other post: TypeScript 2.1.4 breaking changes in webpack ts-loader

简而言之,我将Gulp和WebPack设置为/client/app.ts的入口点,目前它几乎没有任何内容(肯定没有引用/server/的内容),但是WebPack构建过程的TypeScript编译阶段是仍然尝试在/server上运行(在我的另一篇文章中,当它仅应从Client文件夹运行时,显示Server文件夹的编译错误).

In short, I have Gulp and WebPack set to an entry point of /client/app.ts which for now has almost nothing in it (certainly nothing referencing /server/) but the TypeScript compilation stage of the WebPack build process is still trying to run on /server (and in my other post, showing a compilation error from the Server folder, when it should only be running from the Client folder).

我在做什么错,我该如何解决它,使其仅在/client/.ts文件上运行,并且特别是从app.ts遍历结构?

What am I doing wrong and how can I fix it so it only runs on /client/.ts files, and specifically walk the structure from app.ts?

这是我的仓库,显示了到目前为止我正在使用的所有内容: https://github.com/CmdrShepardsPie/test-ts-app/tree/develop

Here's my repo showing everything I'm working with so far: https://github.com/CmdrShepardsPie/test-ts-app/tree/develop

谢谢

推荐答案

您可以通过在webpack.config.js中指定选项onlyCompileBundledFiles来解决此错误

You can work around this bug by specifying the option onlyCompileBundledFiles in your webpack.config.js like so

module: {
    rules: [
        {
            test: /\.tsx?/,
            use: [{loader: 'ts-loader', options: {onlyCompileBundledFiles: true}}],
        }
    ],
},

我仍然感到惊讶的是,ts-loader默认情况下已损坏,但是至少有一种解决方法.

I still find it astonishing that ts-loader is broken by default, but at least there's a workaround.

这篇关于当我只希望WebPack ts-loader在一个文件夹/文件中运行时编译所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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