0

I have a folder with some mock data in "src/api/mock" folder which contains some ts and JSON files. I want Webpack to exclude them when it builds for production. I tried using the below rule but its not working. Any suggestions?

  module: {
    rules: [
      {
        test: /\.(ts|json)$/i,
        exclude: ['/src/api/mock/'],
      },
    ],
  },
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
adnan_aust
  • 45
  • 8

2 Answers2

0

Try this if it works

const path = require('path');

module.exports = {
  ...others,
  module: {
    rules: [
      {
        test: /\.(ts|json)$/,
        exclude: path.resolve(__dirname, 'src/api/mock'),
        use: {
          loader: 'babel-loader',
        },
      },
    ],
  },
};
Mallikarjun M G
  • 509
  • 4
  • 9
  • this causes an error for service worker 1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details) – adnan_aust Feb 24 '23 at 08:07
  • Let's see whether this would help https://stackoverflow.com/questions/72083968/1-warning-in-child-compilations-use-stats-children-true-resp-stats-child – Mallikarjun M G Feb 24 '23 at 09:34
0

since you are using typescript you should use tsconfig.json. when you init this file you should have this already

 "exclude": ["node_modules"]

Just add the correct path for this '/src/api/mock/' to the array. I think ts-loader follows this file's configuration

Yilmaz
  • 35,338
  • 10
  • 157
  • 202