How to exclude a folder from building next js but still read from it?
P粉478445671
P粉478445671 2023-08-29 00:41:39
0
1
551
<p>I have a folder with many json files. I want to exclude it from the build as it increases the build size. But I also need to get the data from these files and it can't be stored in the database. Is there any way to achieve this? </p> <p>I tried excluding the folder in next.config.js but couldn't find any changes</p>
P粉478445671
P粉478445671

reply all(1)
P粉322319601

First, you need to exclude the folders in next.config.js, assuming all the data you need to exclude is in the data folder:

const nextConfig = {
  // ...
  exclude: ['data'],
};

Secondly, you need to import the data folder using require in order to use json data:

const users = require('./data/users.json');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!