简体   繁体   中英

webpack ts-loader not excluding files

I have the following webpack rule setup for typescript.

    rules: [
      {
        test: /\.tsx?$/,
        exclude: [
          /node_modules/,
          /server/gi,
          path.resolve(__dirname, '../src/server.ts'),
          path.resolve(__dirname, '../src/server.worker.ts'),
          path.resolve(__dirname, '../src/network/ServerNetwork.ts'),
        ],
        use: {
          loader: 'ts-loader',
          options:{
            compilerOptions: {
              module: "esnext"
            }
          }
        }
      },

When I run webpack I get an error that indicates one of the excluded files is being processed.

ERROR in /Users/kevzettler/code/hypeworks/src/server.worker.ts
[tsl] ERROR in /Users/kevzettler/code/hypeworks/src/server.worker.ts(96,3)
      TS2304: Cannot find name 'subscribeToMasterMessages'.

I would expect this not to be an issue because this webpack config should be excluding this file. Why is my exclude condition not being met?

the path.resolve s expand to absolute paths that are valid files

console.log(
  path.resolve(__dirname, '../src/server.ts'),
  path.resolve(__dirname, '../src/server.worker.ts'),
  path.resolve(__dirname, '../src/network/ServerNetwork.ts')
);

/Users/kevzettler/code/hypeworks/src/server.worker.ts

Perts-loader doc ,

The default behavior of ts-loader is to act as a drop-in replacement for the tsc 
command, so it respects the include, files, and exclude options in your tsconfig.json,
loading any files specified by those options.

So it should work by adding exclude in tsconfig.json.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM