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

Support for importWorkboxFrom: <chunkname> and associated fixes #1141

Merged
merged 4 commits into from
Dec 19, 2017

Conversation

jeffposnick
Copy link
Contributor

R: @prateekbh @gauntface @goldhand

This is another follow-up to #933, but doesn't close it yet, as there's still a TODO: to implement importWorkboxFrom: 'local'. This PR was large enough already so I wanted to break it up further.

I included a refactoring of a decent chunk of get-manifest-entries-with-webpack.js in this PR, because I discovered that it wasn't properly filtering out all assets based on the chunks/excludeChunks whitelist/blacklist. That became an issue since importWorkboxFrom: <chunkname> is supposed to implicitly add <chunkname> to the blacklist.

This also includes a few more relevant tests, both to ensure that importWorkboxFrom: <chunkname> works as expected, as well as ensure that whitelist/blacklist behavior works in general.

Finally, I discovered that errors which occurred in the previous codebase would lead to a promise being rejected within the plugin's execution, but that failure wouldn't be bubbled up as a webpack error. This refactors the error detection so that asynchronous failures will be properly reported via the webpack callback (and includes a test for that condition).

Copy link

@gauntface gauntface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few minor comments - largely minor refactors.

Is there any chance you could write up some of the higher level approaches taken in the webpack plugin on the Wiki.

Specifically, I don't know the different between a chunk and asset or who they are introduced into a webpack build process. A wiki page with just little info would be super helpful.

}

default: {
for (const chunk of compilation.chunks) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment here on what the intended behavior is. My initial thoughts from the bug was that importWorkboxFrom had to be a specific value but it looks like importWorkboxFrom: 'foo' is valid, but I'm not sure what happens.

for (const chunk of compilation.chunks) {
if (chunk.name === importWorkboxFrom) {
workboxSWImport = chunk.files;
this.config.excludeChunks = (this.config.excludeChunks || [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move this initialisation out of this switch statement just to seperate the initialisation and the addition of the chunk name.

const manifestFilename = `precache-manifest.${fileManifestHash}.js`;
compilation.assets[manifestFilename] = fileManifestAsset;

this.config.importScripts = (this.config.importScripts || [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the initialisation be moved as well.

@@ -31,8 +31,7 @@ function sanitizeConfig(config) {
const propertiesToRemove = [
'chunks',
'excludeChunks',
'filename',
'manifestFilename',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these completely removed as options or is it just moved logic wise to somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're removed (and hardcoded for the time being; some of this will be revised when we support GenerateSW vs. InjectManifest).

@jeffposnick
Copy link
Contributor Author

jeffposnick commented Dec 19, 2017

Thanks; I've written up the state of the webpack stuff at https://github.com/GoogleChrome/workbox/wiki/webpack%2C-assets%2C-and-chunks-%28oh-my%21%29, which was a good exercise anyway.

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.15 KB 3.17 KB +1% 1.34 KB
packages/workbox-broadcast-cache-update/build/workbox-broadcast-cache-update.prod.js 1.06 KB 1.05 KB -1% 565 B
packages/workbox-cache-expiration/build/workbox-cache-expiration.prod.js 3.23 KB 3.25 KB +0% 1.20 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 590 B 593 B +1% 343 B
packages/workbox-core/build/workbox-core.prod.js 6.36 KB 6.67 KB +5% 2.61 KB
packages/workbox-google-analytics/build/workbox-google-analytics.prod.js 1.92 KB 1.94 KB +1% 985 B
packages/workbox-precaching/build/workbox-precaching.prod.js 5.05 KB 4.86 KB -4% 1.89 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.65 KB 1.66 KB +0% 817 B
packages/workbox-routing/build/workbox-routing.prod.js 2.74 KB 2.74 KB -0% 1.23 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 3.23 KB 3.22 KB -0% 1.00 KB
packages/workbox-sw/build/workbox-sw.js 1.46 KB 1.46 KB -0% 792 B
packages/workbox-webpack-plugin/build/index.js 7.29 KB 10.30 KB +41% 3.09 KB ☠️

New Files

No new files have been added.

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.15 KB 3.17 KB +1% 1.34 KB
packages/workbox-broadcast-cache-update/build/workbox-broadcast-cache-update.prod.js 1.06 KB 1.05 KB -1% 565 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 2.52 KB 2.52 KB 0% 1.06 KB
packages/workbox-cache-expiration/build/workbox-cache-expiration.prod.js 3.23 KB 3.25 KB +0% 1.20 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 590 B 593 B +1% 343 B
packages/workbox-cli/build/app.js 4.57 KB 4.57 KB 0% 1.65 KB
packages/workbox-cli/build/bin.js 2.53 KB 2.53 KB 0% 1.07 KB
packages/workbox-core/build/workbox-core.prod.js 6.36 KB 6.67 KB +5% 2.61 KB
packages/workbox-google-analytics/build/workbox-google-analytics.prod.js 1.92 KB 1.94 KB +1% 985 B
packages/workbox-precaching/build/workbox-precaching.prod.js 5.05 KB 4.86 KB -4% 1.89 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.65 KB 1.66 KB +0% 817 B
packages/workbox-routing/build/workbox-routing.prod.js 2.74 KB 2.74 KB -0% 1.23 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 3.23 KB 3.22 KB -0% 1.00 KB
packages/workbox-sw/build/workbox-sw.js 1.46 KB 1.46 KB -0% 792 B
packages/workbox-webpack-plugin/build/index.js 7.29 KB 10.30 KB +41% 3.09 KB ☠️

Workbox Aggregate Size Plugin

☠️ WARNING ☠️

We are using 152% of our max size budget.

Total Size: 22.25KB
Percentage of Size Used: 152%

Gzipped: 8.85KB

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 85.022% when pulling 6579922 on webpack-option-changes into 8b4980b on v3.

@jeffposnick jeffposnick merged commit d391a0c into v3 Dec 19, 2017
@jeffposnick jeffposnick deleted the webpack-option-changes branch December 19, 2017 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants