ifdef-loader icon indicating copy to clipboard operation
ifdef-loader copied to clipboard

How to config for .ts file?

Open TerryChan opened this issue 3 years ago • 2 comments

There are config webpack example for .tsx file in the Readme, and it worked for .tsx file in my project, but it's not work for .ts file when I add #if comment in .ts file. The code below is my webpack config, it used awesome-typescript-loader for .tsx file, and added resolve for .ts, .tsx file:

  module: {
    rules: [
      {
        test: /\.tsx?$/,
        include: path.resolve(__dirname, 'src'),
        use: [
          {
            loader: 'awesome-typescript-loader',
            options: {
                  useBabel: true,
                  useCache: true,
                },
          },
          { loader: 'ifdef-loader', options: opts },
        ],
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.js', '.ts', '.tsx'],
    modules: [path.resolve(__dirname, 'node_modules/'), 'node_modules'],
  },

Anyone know how to make it work for .ts file?

TerryChan avatar Dec 21 '21 16:12 TerryChan

it should work with .ts files as well, the regex /\.tsx?$/ in line 4 matches both .tsx and .ts.

Also .tsx is a superset of .ts, so what works for it works also for .ts.

nippur72 avatar Dec 22 '21 14:12 nippur72

Yes, you are right, it also works for .ts file. And it's working well in my project now. It was my mistake, I tested in the file that out of the include field, which means out of the src folder. Thanks for your reply.

TerryChan avatar Dec 28 '21 18:12 TerryChan