better handling of external modules #18
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I see that this issue has recently been resolved with this PR.
While I understand the need for fine-grained control over which modules are included in the deployed artifact, I am concerned that the current approach is error prone and sub-optimal for two reasons:
A user is forced to explicitly state which modules should be included in the deploy. I suspect many users will add a dependency to the package.json during local dev, then forget to add it to serverless.yml. There should be a single source of truth, the package.json. At the very least, it would have been better to use "webpackExcludeModules" instead of "webpackIncludeModules".
I think it is too naive to simply do another npm install in the artifact directory. Which code is included in the final bundle should be determined in the webpack.config.js using the externals property (single source of truth again). This will also let users take advantage of the tree-shaking feature in webpack v2, which can dramatically reduce the artifact size being uploaded.
I suggest simply setting an environment variable during deployment, that the user can check for in their webpack config file. For example, while testing this PR I added the following to my webpack config:
This PR can coexist with the current approach, but I would suggest reverting the earlier merge as it might be confusing to have two different ways of achieving the same thing.
Please let me know if you find anything wrong with my reasoning. Thanks.