Hi all I am trying to write a Netlify plugin for my svelte-kit app following this blog post: How can build plugins can optimize your code for maximum efficiency in production? In this tutorial, learn how to localize your env vars by context. Check it out!
Netlify specifically looks for an
index.js for their plugins as shown in this subreddit answer:
When we create a brand new svelte-kit app, the
type: module specified. Because of that, running
netlify build to try the build locally fails because:
Could not import plugin: ReferenceError: module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/Users/website/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
But, if I change the extension to
.cjs, Netlify doesn’t find the plugin as it looks specifically for
index.js as mentioned before.
Has anyone had this problem? And how have you dealt with it?
I have pushed a demo version of my problem in this repo:
Thanks for your help!