Closed prichey closed 3 years ago
I haven't added this in the past, since you can easily do this instead:
skipIndexing: process.env.SKIP_ALGOLIA_INDEXING === 'true' && {
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_API_KEY,
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
queries: [],
},
},
but I understand that might be a bit unintuitive. Maybe we just need to put it in the readme?
Are there other Gatsby plugins that have a "disable" flag?
@Haroenv Good point. I'm not aware of any other plugins that have that pattern. For what it's worth, this plugin is the only one we're using that writes data (to a service that charges for writing data) every time you build. Still, we can totally get away with conditionally spreading like you showed rather than merging my PR if you'd prefer not to.
Closing this issue since I can just conditionally append the plugin
I think it might make sense to document that in the readme maybe?
When I conditionally add the plugin, Gatsby resets the build cache since the plugins changed, which leads to slightly longer build times. Has anyone been able to work around this?
Are there other Gatsby plugins that have a "disable" flag?
The unofficial Sentry plugin for Gatsby sort of has a disabled flag:
// In your gatsby-config.js
plugins: [
{
resolve: "gatsby-plugin-sentry",
options: {
dsn: "YOUR_SENTRY_DSN_URL",
// Optional settings, see https://docs.sentry.io/clients/node/config/#optional-settings
environment: process.env.NODE_ENV,
enabled: (() => ["production", "stage"].indexOf(process.env.NODE_ENV) !== -1)()
}
}
];
However, I'm not entirely sure how they implemented the flag (it could just be passed down to the Sentry SDK?), so this might not be the best example.
it's just forwarded to the sentry plugin: https://github.com/octalmage/gatsby-plugin-sentry/blob/master/gatsby-browser.js#L4
If we do this too, I'm not sure whether we should do anything at all (exit immediately) or just not index. Does anyone have an opinion here?
The cache problem is very valid!
I think it's reasonable to just immediately exit like how it's implemented in #99 (what would the plugin do other than indexing?)
Makes perfect sense, released as 0.16.0
I've often thought it'd be useful to have an option in settings to skip indexing. This should obviously default to false, but it'd allow the Gatsby site to safely be rebuilt if the index shouldn't be updated.
A valid config might look something like:
@Haroenv any thoughts?