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/'], }, ], }, 
4
  • Does this answer your question? How to exclude directory from getting bundled by Webpack? Commented Feb 24, 2023 at 7:07
  • no none of the solutions working for me Commented Feb 24, 2023 at 7:11
  • are u using typescript? Commented Feb 24, 2023 at 7:13
  • yes, I am using ts Commented Feb 24, 2023 at 8:02

2 Answers 2

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', }, }, ], }, }; 
Sign up to request clarification or add additional context in comments.

2 Comments

this causes an error for service worker 1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
Let's see whether this would help stackoverflow.com/questions/72083968/…
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.