floydspace/serverless-esbuild

feature: pass serverless instance to plugins config

bauer01 opened this issue ยท 3 comments

Hi,
it would be nice to pass the whole serverless instance as we need to configure esbuild plugins according to our serverless settings.

Something like this maybe?

custom:
  esbuild:
    plugins: plugins.js

and

const getSecretConfigEnvs = (slsw) => {
	const { custom } = slsw.lib.serverless.service
	const secretConfigEnvs =
		custom && custom.secretConfigEnvs ? custom.secretConfigEnvs : {}

	return {
		'process.env.__SECRETS__': JSON.stringify(secretConfigEnvs)
	}
}

module.exports = (serverless) => {
	const definePlugin = {
		name: 'auto-node-env',
		setup(build) {
			const options = build.initialOptions
			options.define = options.define || {}
			options.define = {
				...options.define,
				...getSecretConfigEnvs(serverless)
			}
		}
	}

	return [
		definePlugin
	]
}

What do you think?

Hi @bauer01, thank you for the feature request, yes it does make sense on certain occasions. so I implemented it.
Could you please check it in version 1.17.0
And apologize for the slow response.

๐ŸŽ‰ This issue has been resolved in version 1.17.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

Thank you so much! @floydspace ๐Ÿ‘