feat(project): update definitions when the bundle gets reloaded #77
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.
What does this PR do?
This is a follow up for #74.
Variables from
.env
files and browser target configurations were being loaded and sent to thewebpack.DefinePlugin
, but the problem was that if a variable would change, even after triggering a bundle reload, its value wouldn't be updated on the target code nor its configuration.Short version: Definitions are now refreshed every time the bundle gets reloaded.
And now, for the long a breaking version:
The first thing I did was to convert the
params.definitions
the engine moves around from an object into a function that would return the object.Then,
webpack.DefinePlugin
allows for computed definitions as functions... but each key needs to be function, you can't have a single one that would return everything; so I created a webpack plugin that wrapswebpack.DefinePlugin
and supports a single function.Finally, I replaced
webpack.DefinePlugin
on the browsers' configurations with the new plugin.Now, this is very important: because using computed definitions without specifying a file that depends on the definition marks ALL files as "non-cachable", which makes the build slower, the build engine only reloads the definitions when the target entry file changes. Yes, it's not the best solution, but the alternative would be slower builds.
How should it be tested manually?
In order to test this, you need to install
homer0/projext#next
and make sure you delete the copy ofprojext
npm
/yarn
will install inside this package'snode_modules
.Create a browser target, and
.env
file with a declared variable and configuration for the target that uses the variable.Then run your target and check if the configuration has the right value. Update the variable on the
.env
file and "save the target entry file" (cmd/ctrl+s would trigger the rebuild), the configuration should have the new value.And, of course...