用npm安装CKEditor

Hec*_*nez 4 ckeditor node.js laravel gulp laravel-elixir

我正在尝试在我的项目中安装CKEditor.我正在使用Laravel.

我知道我可以下载文件,但我喜欢让我的生活变得困难,我决定将CKEditor安装为npm依赖项.

正如他们在这里的文档中所述,我将包添加到package.json,如下所示:

"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"
}
Run Code Online (Sandbox Code Playgroud)

现在我想我必须在app.coffee中要求它,所以我尝试了:

window.$ = window.jQuery = require('jquery')
require('bootstrap-sass')
require('ckeditor')
Run Code Online (Sandbox Code Playgroud)

这肯定会将ckeditor.js脚本添加到我的app.js. 但是ckeditor似乎有自己的依赖项,例如config.js或editor.css,当然服务器对这些请求的响应为404.

我怎么能这样安装CKeditor?

谢谢!

f1a*_*mes 11

这些CKEditor依赖项的路径可能存在问题.我不确定你是使用browserify还是其他不同的东西但是例如在browserify中使用require('ckeditor')会导致ckeditor.js(可能与其他js文件捆绑在一起)文件从文件加载到app.coffee文件,而CKEditor依赖项在node_modules/ckeditor/dir中.

要告诉CKEditor它应该从哪个目录加载它的依赖项,你可以使用CKEDITOR_BASEPATH:

window.CKEDITOR_BASEPATH = 'node_modules/ckeditor/'
require('ckeditor')
Run Code Online (Sandbox Code Playgroud)

您可能会看到在开发控制台中使用" 网络"选项卡加载这些文件时是否存在问题(例如Chrome中的F12).

请注意,它不是生产环境的理想解决方案,因为您需要node_modules在服务器上使用文件夹.您应该考虑在构建/释放过程中仅将这些依赖项移动到其他文件夹(并像以前一样使用CKEDITOR_BASEPATH以及此生产文件夹的路径).