Open dev-seahouse opened 7 years ago
;
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(function () {
root = window; // <========= this fixed it, the problem seem to be 'root' is not window object for some reason
return factory(root)
})
} else if (typeof exports === 'object') {
module.exports = factory
} else {
root.progressively = factory(root)
}
})(this, function (root) {
'use strict'
This seems to be happening because root
is not defined when the factory
function is exported. I'll find a workaround soon and post it in this thread.
Till then, you could use webpack's external configuration. Hope that will solve your problem.
@thinker3197 Did you find any solution? I kind of running in the same issue.
I tried out a few other plugins and this is a common issue when using js/jquery libraries with webpack. This happens, as I stated above because webpack wraps the package in it's own object while bundling thus loosing the access to window
object. You can use the above mentioned solution if that helps!
Then.. I guess I will use the CDN version for now. Thanks.
@dev-seahouse
In my environments, this would work. (webpack 3)
in webpack.config.js:
module: {
rules: [
...
{
test: /progressively.*\.js$/,
loader: 'imports-loader?this=>window',
},
],
},
in js:
import progressively from 'progressively';
progressively.init();
Thanks @koishimasato for sharing the solution. I'll try it out later.
@koishimasato solution doesn't work with webpack 4. Any ideas?
; (function (root, factory) { if (typeof define === 'function' && define.amd) { define(function () { root = window; // <========= this fixed it, the problem seem to be 'root' is not window object for some reason return factory(root) }) } else if (typeof exports === 'object') { module.exports = factory } else { root.progressively = factory(root) } })(this, function (root) { 'use strict'
Yep , this works 👍
import progressively from 'progressively/src/progressively';
i got the following error in dev tool and yet it is still working.
What i did: