Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(project): update definitions when the bundle gets reloaded #77

Merged
merged 6 commits into from
Jul 31, 2019

Conversation

homer0
Copy link
Owner

@homer0 homer0 commented Jul 31, 2019

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 the webpack.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 wraps webpack.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 of projext npm/yarn will install inside this package's node_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...

yarn test
# or
npm test

@coveralls
Copy link

coveralls commented Jul 31, 2019

Pull Request Test Coverage Report for Build 279

  • 43 of 43 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 276: 0.0%
Covered Lines: 646
Relevant Lines: 646

💛 - Coveralls

@homer0 homer0 changed the base branch from homer0_fixCSSLoader to next July 31, 2019 10:15
@homer0 homer0 merged commit 20b24de into next Jul 31, 2019
@homer0 homer0 deleted the homer0_defineOnReload branch July 31, 2019 10:15
@homer0 homer0 added the on:next label Jul 31, 2019
@homer0 homer0 mentioned this pull request Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants