当我只希望它在一个文件夹/文件中运行时,WebPack ts-loader 编译所有文件 [英] WebPack ts-loader compiling all files when I only want it to run in one folder/file
问题描述
我在使用 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 上运行(在我的另一篇文章中,显示服务器文件夹中的编译错误,而它应该只从客户端文件夹中运行).
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屋!