A hacky attempt at supporting createSharedEntry() in Webpack 4 #339
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.
There is currently on big problem with the Webpack 4 support (#324):
createSharedEntry()
no longer works as expected.Suppose this config:
Where
assets/layout.js
looks like this:In Webpack 3, the
console.log()
code WOULD run. But, in Webpack 4, the finallayout.js
file simply contains the code for all of the modules... but unless someone actually requires them, their code is not executed. As a result, unless some other entry explicitly hadrequire('./assets/layout.js')
, theconsole.log()
would never actually execute.This, unfortunately, is a big change in behavior, and it no longer allows you to use
createSharedEntry()
to identify a "layout" file whose code you want included (and executed) on every page.There are 2 solutions:
A) A hacky solution to support
createSharedEntry()
, at least temporarily (this PR!)B) Stop supporting
createSharedEntry()
, and "force" people to use Webpack 4's new code splitting, where each entry may ultimately require multiple<script>
tags. We will need a new bundle to support this behavior anyways. But, in this scenario, this would be the MAIN way to use webpack, unless you have an SPA and don't care about this shared stuff.I would love feedback - this has been blocking #324, and keeping me up at night ;). I also may be missing something: the new split chunks functionality is very powerful, but complex.