Closed OmgImAlexis closed 6 years ago
Here's how I've done it:
import PNotify = require("pnotify");
require('pnotify/src/pnotify.buttons');
require('pnotify/src/pnotify.desktop');
@hperrin any interest in making this library more es6-friendly or perhaps using typescript?
@codymullins I'd rather not use that method since it creates side effects. I was hoping there would be something I could import and then load into PNotify.
Something like this maybe.
import PNotify from 'pnotify';
const notify = new PNotify({
plugins: ['desktop']
});
Also I think you meant import PNotify from "pnotify";
or const PNotify = require("pnotify");
.
@OmgImAlexis I use the import syntax above import PNotify = require("pnotify");
, but that's using Typescript so it likely is what you've suggested for ES6.
I agree about the side effects, unfortunately I haven't really found any other way. To be honest looking through the source it would probably take a little refactoring to improve upon this, but I could be wrong - the billion different ways to import things these days is something that still confuses me.
I think since the code is fairly old it could use with some updating in terms of either ES6 or Typescript. Ultimately that's up to @hperrin though.
In the meantime, could the Readme please include "This library does not support ES6 module importing" at the top so those of us who need it don't waste our time with this?
@codymullins Yeah, version 4.0 will be written in ES2017 and compiled to ES5 with Babel. It will also use Svelte instead of jQuery. (Svelte compiles to vanilla JS, so no dependencies.) Right now, I'm working out the best way to do that while maintaining as much backward compatibility as is reasonably possible.
@joshnoe I'm not interested in listing the technologies that aren't supported by my libraries. The readme already explains that PNotify uses AMD/RequireJS when they are detected.
I've been working on version 4, and there is a working version now (though it's still a bit buggy). You can check out the 4.0-dev
branch to see it.
Fixed in develop branch. (v4) There will be ES6 module builds in NPM with v4.
What's the recommended way to use this with ES6 module importing?
I've tried using
import PNotify from 'pnotify';
but that doesn't allow me to use the desktop module or override the prototype. I'm also using webpack if that changes anything.