Change file without triggering a reload of Strapi

Hello,
I’m creating a plugin that requires creating files, the problem (I think) is that Strapi is reloading before I’m done creating all the files, thus breaking.

How could I delay or stop the refresh of Strapi?

Thanks

Forgot to add a await in /config/functions/bootstrap.js, I think that is what fixed the issue

    watchIgnoreFiles: [
      './my-custom-folder', // Folder
      './scripts/someScript.sh', // File
    ],
1 Like

and where this setting supposed to sit in? following the documentation didn’t help too.
I created a “./config/development/server.json” file ( my NODE_ENV set to “development”) and added to it:

{
    "host": "localhost",
    "port": 1337,
    "proxy": {
      "enabled": false,
      "ssl": true,
      "host": "example.com",
      "port": 8443
    },
    "cron": {
      "enabled": false
    },
    "admin": {
        "watchIgnoreFiles": [
            "./scratch.js"
          ]
    }
  }

but strapi server still restarts whenever I change contents of scratch.js file!!

This isn’t working for me either. I have this in my config/server.js.

Is this the right approach? The documentation doesn’t actually have an example.

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', '...')
    },
    watchIgnoreFiles: [
      './test.txt',
    ]
  }
})

Changing the test.txt file forces server restart.

@Toby, try using **/test.txt instead

1 Like

Thank you, that worked. Not sure why, though… I wonder what the current working directory is from the context of that server file.

Just fyi, I had to put it to my /config/admin.js for it to work:

module.exports = ({ env }) => ({
  // some other variables are here
  watchIgnoreFiles: [
    './logs',
    '**/logs'
  ]
});
2 Likes

Yup indeed, we move this over to the admin.js file in v4 even though it does affect the server. The main purpose was for the --watch-admin flag but it does watch during a regular develop command run also.

Glad you got it figured out!