Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing CKEditor with npm

I am trying to install CKEditor in my project. I am using Laravel.

I know I could download the files but I like making my life difficult and I decided that I want to install CKEditor as a npm dependency.

As stated in their documentation here, I added the package to package.json, like this:

"dependencies": {
    "jquery": "^1.11.1",
    "bootstrap-sass": "^3.0.0",
    "elixir-coffeeify": "^1.0.3",
    "laravel-elixir": "^4.0.0",
    "font-awesome": "^4.5.0",
    "ckeditor": "^4.5.7"
}

Now I guess I have to require it in my app.coffee, and so I tried:

window.$ = window.jQuery = require('jquery')
require('bootstrap-sass')
require('ckeditor')

This surely adds the ckeditor.js script to my app.js. However ckeditor seems to have its own dependencies such as config.js or editor.css, and of course the server responds with 404 for those requests.

How could I install CKeditor this way?

Thank you!

like image 984
Hector Ordonez Avatar asked Mar 17 '16 15:03

Hector Ordonez


People also ask

How do I enable source in CKEditor?

Classic Editor with Default Source Editing AreaClick the Source button to display the HTML source of this text in the source editing area. Click the Source button again to return to the WYSIWYG view.


1 Answers

There is probably a problem with paths to those CKEditor dependencies. I'm not sure if you are using browserify or something different but for example in browserify using require('ckeditor') will result in ckeditor.js (bundled probably with other js files) file loading from same dir as your app.coffee file while CKEditor dependencies are in node_modules/ckeditor/ dir.

To tell CKEditor from which directory it should load its dependency you may use CKEDITOR_BASEPATH:

window.CKEDITOR_BASEPATH = 'node_modules/ckeditor/'
require('ckeditor')

You may see if there is a problem with loading those files using Network tab in Dev console (e.g. F12 in Chrome).

Note that it's not ideal solution for production environment because then you need node_modules folder on your server. You should probably consider moving only those dependencies to other folder during building/releasing process (and use CKEDITOR_BASEPATH as before with path to this production folder).

like image 150
f1ames Avatar answered Sep 19 '22 01:09

f1ames