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 importWorkboxFrom: 'local' in the InjectManifest webpack plugin #1290

Merged
merged 6 commits into from Feb 13, 2018

Conversation

jeffposnick
Copy link
Contributor

@jeffposnick jeffposnick commented Feb 9, 2018

R: @gauntface
CC: @raejin

Fixes #1260

This adds importWorkboxFrom: 'local' support to the InjectManifest webpack plugin. (It's still not supported in injectManifest mode of the workbox-build or workbox-cli.)

Assuming this PR is merged, I'll need to update https://github.com/google/WebFundamentals to reflect the new config.

@@ -80,10 +80,13 @@ describe(`[workbox-webpack-plugin] GenerateSW (End to End)`, function() {
const compiler = webpack(config);
compiler.run((webpackError) => {
if (webpackError) {
expect(webpackError.message.includes('importWorkboxFrom'));
done();
if (webpackError.message.includes('importWorkboxFrom')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, in the course of writing this PR, I discovered that this test pattern wasn't actually working as it was initially implemented: it should have been expect(webpackError.message.includes('importWorkboxFrom')).to.be.true, although that would then cause an unhandled promise rejection rather than a clean error to report back to mocha.

I took the opportunity to clean up this test along with the corresponding test in the inject-manifest.js suite so that it properly detects the failure and reports it using the done() callback.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 89.153% when pulling 4a85cf2 on inject-manifest-local into 50fab16 on v3.

const postInjectionSWString = `importScripts(${importScriptsString});
const setConfigString = modulePathPrefix
? `workbox.setConfig({modulePathPrefix: ` +
`${JSON.stringify(modulePathPrefix)}});`
Copy link

Choose a reason for hiding this comment

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

Do you think JSON.stringify is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's safer than wrapping the value in either "..." or '...', just on the off chance modulePathPrefix contains any quote characters. (Not that it should, but still.)

JSON.stringify() is guaranteed to return a properly escaped string.

});
});

it(`should support setting importWorkboxFrom to 'local'`, function(done) {
Copy link

Choose a reason for hiding this comment

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

It'd be cool to include a test where Webpack publicPath is specified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-webpack-plugin/build/inject-manifest.js 8.48 KB 8.82 KB +4% 2.89 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.27 KB 3.27 KB 0% 1.39 KB
packages/workbox-broadcast-cache-update/build/workbox-broadcast-cache-update.prod.js 1.07 KB 1.07 KB 0% 573 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.41 KB 3.41 KB 0% 1.26 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 594 B 594 B 0% 350 B
packages/workbox-cli/build/app.js 5.09 KB 5.09 KB 0% 1.86 KB
packages/workbox-cli/build/bin.js 2.32 KB 2.32 KB 0% 1.03 KB
packages/workbox-core/build/workbox-core.prod.js 6.40 KB 6.40 KB 0% 2.54 KB
packages/workbox-google-analytics/build/workbox-google-analytics.prod.js 2.07 KB 2.07 KB 0% 1.02 KB
packages/workbox-precaching/build/workbox-precaching.prod.js 5.18 KB 5.18 KB 0% 2.02 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.64 KB 1.64 KB 0% 807 B
packages/workbox-routing/build/workbox-routing.prod.js 2.77 KB 2.77 KB 0% 1.25 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 3.24 KB 3.24 KB 0% 1.01 KB
packages/workbox-sw/build/workbox-sw.js 1.46 KB 1.46 KB 0% 793 B
packages/workbox-webpack-plugin/build/generate-sw.js 6.41 KB 6.41 KB 0% 2.17 KB
packages/workbox-webpack-plugin/build/index.js 742 B 742 B 0% 470 B
packages/workbox-webpack-plugin/build/inject-manifest.js 8.48 KB 8.82 KB +4% 2.89 KB

Workbox Aggregate Size Plugin

☠️ WARNING ☠️

We are using 154% of our max size budget.

Total Size: 22.52KB
Percentage of Size Used: 154%

Gzipped: 9.01KB

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.

This looks good to me.

@raejin
Copy link

raejin commented Feb 28, 2018

@gauntface @jeffposnick

After testing out v3.0.0-beta.1, I think this is not compatible with static asset that gets served from a different domain. By tracing the source a bit, we are copying the file on the disk instead of copying the file to the Webpack compilation.

https://github.com/raejin/workbox/blob/17c38de990585d7076b03ecca55d33b3166e53e9/packages/workbox-build/src/lib/copy-workbox-libraries.js#L78-L79

What do you guys think of a different implementation on copying on disk versus Webpack compilation?

@jeffposnick
Copy link
Contributor Author

Rather than discussing this on a merged PR, I created #1338

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.

None yet

5 participants