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

importScripts not loading #186

Open
brunosc opened this issue May 16, 2018 · 2 comments
Open

importScripts not loading #186

brunosc opened this issue May 16, 2018 · 2 comments

Comments

@brunosc
Copy link

brunosc commented May 16, 2018

Hi folks,

I'm adding sync task to my service worker but it's doesn't work.

adm-webapp/build/webpack.prod.conf.js

new SWPrecacheWebpackPlugin({
      cacheId: 'adm-webapp',
      filename: 'service-worker.js',
      staticFileGlobs: ['dist/**/*.{js,html,css}'],
      minify: true,
      stripPrefix: 'dist/',
      importScripts: [
        { fileName: utils.assetsPath('js/custom-sw.js') }
      ]
     ...

adm-webapp/static/js/custom-sw.js

self.addEventListener('sync', function(event) {
    console.log('[Service Worker] Background syncing', event);
    console.log(event.tag);
})

If I look "source" tab on Chrome, the custom-sw.js is not loaded

So I added this import script but still not working

adm-webapp/index.html
<script type="text/javascript" src="<%= htmlWebpackPlugin.files.publicPath %>static/js/custom-sw.js"></script>

What's wrong?

@eeerrrttty
Copy link

please, someone give us a light!

@eeerrrttty
Copy link

I loaded my custom-service worker with the following:

        new CopyWebpackPlugin([
          {
            from: path.resolve(__dirname, '../static'),
            to: config.build.assetsSubDirectory,
            ignore: ['.*']
          },
          {
            // copy custom service worker
            from: path.resolve(__dirname, '../src/firebase-messaging-sw.js'),
            to: config.build.assetsRoot + '/[name].js',
            transform: (content, path) => {
              // and transpile it while copying
              return babel.transformFileSync(path).code
            }
          }
        ]),
        // service worker caching
        new SWPrecacheWebpackPlugin({
            cacheId: 'teste',
            importScripts: [
              {
                // transformed custom-service-worker (es6 -> js)
                filename: 'firebase-messaging-sw.js'
              }
            ],
            filename: 'service-worker.js',
            staticFileGlobs: ['dist/**/*.*'],
            minify: true,
            stripPrefix: 'dist/'
        })

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

No branches or pull requests

2 participants