-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Individually packaging with multi-modules entry does not work #397
Comments
Hi @geovanisouza92 , the whole entries mechanism is needed to pickup the right entry again after the compile has been finished and associate the entry name returned from Webpack together with the compile results back to the right serverless function that the compile is for. I remember that someone copied his custom entries modification into a GitHub issue, prepending the source-map-install and that worked. I do not remember which issue that was but I believe, that he did not add arrays to the entries object, but did something else. I will try to find that again and we can see if that would work here too. I'll provide feedback as soon as I've found the comment. |
Hi @HyperBrain, thanks for the reply! Well, from the template I generated the project, it already include arrays at entry. EDIT: What I mean in my suggestion above is that, picking the key will result in the same result as picking the value and manipulating it. For instance: On my serverless.yml I have a So, as both places use the same Am I missing some thing? Indeed, as far as I remember, the compilation output references the entry name (key), so the same |
@geovanisouza92 Thanks for the "edit" 😄 . The most important point is your very last sentence. As long as the reverse mapping from the Webpack compile stats to the serverless function is unambigous, the behavior should not change. |
So, I started to dig through this implementation and made it work on my fork, but came across a validation that disallow customization like the one I proposed. I didn't noticed this behavior earlier because I was using and older version of serverless-webpack, and since version release v4.1.0 it includes a change described on #272. My suggestion here is that customization should be allowed, but warned, instead throwing a validation error. In fact, looking at the code I noticed that:
My changes so far include:
Possible changes:
P.S.: Maybe an alternative is to adjust |
Hi @geovanisouza92 , thanks for the good and detailed proposal 🎉 As you found correctly, the manual intervention of the entries is blocked since v4. The reason for that is, that for stability everything should be handled by slsw.lib.entries, especially for individual packaging. Turning that into a warning will allow users to break their deployments silently and will decrease the overall plugin stability. So the manual configuration has been deprecated and is not supported anymore. Additionally, allowing the user to set arbitrary will add much technical debt, because the plugin would have to handle each possible case (which can even change when webpack versions change). My suggestion here is, to keep the error, but add other fully controlled mechanisms to add arbitrary modules to a function. The whole approach of the configuration in Serverless and its service definition is declarative and so should be the plugin. Your sample at the end would offer the functionality while keeping the declarativeness of the configuration. We should continue to force to set slsw.lib.entries as entries. What if we just add the possibility to declare additional modules that will be pre- or appended on a function and service level in the serverless.yml. This will solve the issue completely and is easy to understand for users. Any function based config would override the service configuration if any exists. # service based config
custom:
webpack:
entry:
pre:
- source-map-support.js
post:
- myAdditionalModule.js # function override
functions:
foo:
handler: foo.handler
bar:
handler: bar.handler
webpack:
entry:
pre:
- ./injected-dependency.js
post:
- ./foo.js All configurations are optional. IMO this is the only change/extension needed, to have it fully configurable in a deterministic way. What do you think? |
+1000 to entry prepend/append entries per function. I was thinking today about using I'll work on that later. |
So, I've updated my fork following this idea of pre/post (actually prepend/append). Should we support a "global" configuration on |
Yes. As I wrote, the hierarchy is global <- function, i.e. the global config is applied, then the function config if it is present. The effective array contents should then be merged to pertain the order (global then function) |
ANy progress on this? Or a workaround? |
any workaround? |
How does this operate if the functions are using differing runtimes? Eg. I have one function running node and one running python. I can't supply slsw.lib.entries, because webpack can't compile a python function |
This is a Bug Report
Description
I'm customizing entries on webpack to inject common funcionality, like source-map support and tracing modules. If I package functions individually, it does not work.
I tracked the issue to this line where the entry value is an array, and the path module is applied incorrectly.
If I understood correctly:
entry
receives the relative filename of each handlerentryFile
receivesentry
without extensionentryFile
is used to pick the right entry function fromallEntryFunctions
allEntryFunctions
is generated from the entries, wherehandlerFile
is generated from function handlers onserverless.yml
.So, we could just use the
key
that is the entrypoints based on serverless "handler" configurations, and the problem will be solved.For bug reports:
When I enabled individual packaging and use multiple modules for each entry, it throw the error "Path must be a string. Received [ './source-map-install.js', (redacted) ]"
The commands
sls invoke local
andsls webpack
working fine.serverless.yml
webpack.config.js
Additional Data
The text was updated successfully, but these errors were encountered: