How can I use CKEditor from npm with webpack?
Ideally I want npm install ckeditor --save
then var CK = require('ckeditor');
without any global namespace pollution.
Creating a plugin All features in the CKEditor 5 are powered by plugins. In order to create our custom timestamp plugin, we need to import the base Plugin class. We can now create a Timestamp class that extends the basic Plugin class. After we define it, we can add it into the editor's plugins array.
Because CKEditor 4 has an active community that openly develops and shares add-ons, which you are welcome to take part in. Open Source applications are totally free! They do not include adware or limited trial periods, and can be used in commercial projects.
The problem
As far as I can tell it isn't currently possible to load CKEDITOR directly into webpack as a chunck without getting some errors, especially when starting to load additional plugins. One of the reasons for this seems to be that ckeditor does it's own async requests at runtime causing various things to break in nearly all of the implementations I have tried.
The solution
Use scriptjs to load it as an external library.
npm install scriptjs --save
Now in your code you can call it like so:
var $s = require('scriptjs');
$s('./vendor/ckeditor/ckeditor.js', function(){
CKEDITOR.replace('editor1');
});
Please Note.
This will not work on the uncompressed source because the ckeditor functions are not directly in the ckeditor.js file. This will cause the rest of your logic to run before the CKEDITOR object is fully constructed due to unfinished network requests.
If you wish to modify the source code of CKEDITOR clone https://github.com/ckeditor/ckeditor-dev and run it's build script to get a working customised version.
It looks like CKEditor is embracing ES6 in version 5 and I suspect they will have webpack support in this version but who knows how long it will be in development before it is released.
If there is a better way of doing this, please let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With