skip to Main Content

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

2

Answers


  1. 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',
            },
          },
        ],
      },
    };
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search