Open anthonator opened 9 years ago
+1. Would love to be able to use this with webpack easier.
+1
+1
Global vars are for the birds
https://github.com/HubSpot/offline/pull/75/files
I think this PR should have done the trick? Let me know if there's anything else needed to close this.
The issue is that the library sets window.Offline at the bottom of the code. To properly support modules and avoid globals, the code should be wrapped in an IIFE and never reference window directly. Here's an example that detects the environment it's being loaded in and exports either a module or a global --
http://bob.yexley.net/umd-javascript-that-runs-anywhere/
That references a repo of template examples at https://github.com/umdjs/umd
You probably want to use returnExports.js so that it'll continue to work for existing global users.
+1!
If it's AMD loaded then it will probably run after DOMContentLoaded better - so this issue will have to be catered for: https://github.com/HubSpot/offline/issues/209 .
+1 it's really bad because now many people create front code with browserify to have commonJS support or RequireJS for AMD support
+1
I was able to get this working through
const Offline = require('exports?Offline!offline-js/offline');
or import Offline from 'exports?Offline!offline-js/offline';
at the top of my file and
"exports-loader": "0.6.3",
in my package.json
hope that helps!
With browserify, I use offline.js like this and it works (but it's too bad to pass by window
) :
require('offline-js/js/offline');
window.Offline.check();
:factory: Uncaught ReferenceError: exports is not defined
Similar to the comments after #92 was closed. Add CommonJS/AMD wrapper to support us browserify/webpack users.