WebPack ts-loader compiling all files when I only want it to run in one folder/file

戏子无情 提交于 2019-12-06 02:23:53

问题


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.

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

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).

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?

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

Thanks


回答1:


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}}],
        }
    ],
},

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



来源:https://stackoverflow.com/questions/41289265/webpack-ts-loader-compiling-all-files-when-i-only-want-it-to-run-in-one-folder-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!