FOSCKEditorBundle有时有效,有时无效,与bootsnav.js冲突

时间:2019-07-08 14:19:48

标签: javascript symfony symfony4 webpack-encore

我正在使用Symfony 4和webPack Encore捆绑包。我对Fosckeditorbundle有一个奇怪的问题,有时它很好用,有时在控制台中出现错误,我应该刷新浏览器很多次,直到捆绑包生效。

FOSCkeditor捆绑包未通过webpack encore处理,但是问题是在使用webpack encore捆绑包之后出现的。

Uncaught TypeError: Cannot read property 'getClientRect' of null
at p.getClientRect (ckeditor.js:1253)
at p.queryViewport (ckeditor.js:1253)
at new p (ckeditor.js:1238)
at a.<anonymous> (ckeditor.js:1274)
at a.p (ckeditor.js:10)
at a.<anonymous> (ckeditor.js:12)
at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js:13)
at $.<anonymous> (ckeditor.js:944)
at ckeditor.js:30

编辑:

我进行了一些测试,发现问题来自 bootsnav.js ,将其删除时没有任何错误。

1 个答案:

答案 0 :(得分:0)

如果您使用Webpack Encore,则应将FosCKEditorBundle与Webpack Encore一起使用。

  1. 删除您的CKEditor副本(而不是FosCKEditorBundle)。
  2. 通过Webpack Encore 重新安装它。根据{{​​3}},您只需要:

    添加纱线ckeditor@^4.0.0

然后在webpack配置中

var Encore = require('@symfony/webpack-encore');

Encore
    // ...
    .copyFiles([
        {from: './node_modules/ckeditor/', to: 'ckeditor/[path][name].[ext]', pattern: /\.(js|css)$/, includeSubdirectories: false},
        {from: './node_modules/ckeditor/adapters', to: 'ckeditor/adapters/[path][name].[ext]'},
        {from: './node_modules/ckeditor/lang', to: 'ckeditor/lang/[path][name].[ext]'},
        {from: './node_modules/ckeditor/plugins', to: 'ckeditor/plugins/[path][name].[ext]'},
        {from: './node_modules/ckeditor/skins', to: 'ckeditor/skins/[path][name].[ext]'}
    ])

;

如果需要,别忘了更新fos_ckeditor.yaml中的配置路径:

fos_ck_editor:
    # ...
    base_path: "build/ckeditor"
    js_path:   "build/ckeditor/ckeditor.js"

这样,您将避免js冲突。