lukeed / pwa

(WIP) Universal PWA Builder
https://pwa.cafe
3.13k stars 101 forks source link

issue with offline-plugin #21

Closed tuananh closed 6 years ago

tuananh commented 6 years ago

I got this issue with offline plugin. The link in the error recommends that i add this require('offline-plugin/runtime').install(); but i'm not sure where to add it .

OfflinePlugin: Plugin's runtime wasn't added to one of your bundle entries. See this https://goo.gl/YwewYp for details.
lukeed commented 6 years ago

Hey, yeah you need to add it somewhere in your bundle. I recommend this at the bottom of your src/index.js

if (process.env.NODE_ENV === 'production') {
  require('offline-plugin/runtime').install();
}

Similarly, that expects that you added the plugin in production mode only.

exports.webpack = function (config, env) {
  if (env.production) {
    config.plugins.push(
      new OfflinePlugin()
    )
  }
}

That'll do it for ya!

lukeed commented 6 years ago

Verified this locally, and there'll now be a @pwa/plugin-offline in the next release. Similarly, attaching Service Workers will be included in init's scaffolding. 👍