我正在尝试构建一个ember 3.25应用程序,它通过ember-auto-import
导入CkEditor
通过在package.json
中添加以下代码,我能够使编辑器正常工作:
"@ckeditor/ckeditor5-build-classic": "^27.0.0",
并将以下内容添加到我的ember组件中:
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
...
didInsertElement() {
var editor = ClassicEditor
.create( document.querySelector( '#editor' ), {
...
});
}
但当我尝试通过以下方式添加ImageResize
模块时:
"@ckeditor/ckeditor5-image": "^27.0.0",
在我的组件中(如此处所示):
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageResize from '@ckeditor/ckeditor5-image/src/image-resize';
我最初看到的错误如下:所以我运行了AUTO_IMPORT_VERBOSE=true ember serve
我现在看到错误,ckeditor不能@import
嵌套.css
:
ERROR in ./node_modules/@ckeditor/ckeditor5-ui/theme/components/toolbar/toolbar.css 6:0
Module parse failed: Unexpected character '@' (6:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| */
|
> @import "../../mixins/_unselectable.css";
或者使用ES6语法:
ERROR in ./node_modules/@ckeditor/ckeditor5-ui/theme/components/dropdown/toolbardropdown.css 6:0
Module parse failed: Unexpected token (6:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| */
|
> :root {
以及尝试包含SVG文件时出现的错误:
ERROR in ./node_modules/@ckeditor/ckeditor5-widget/theme/icons/drag-handle.svg 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M4 0v1H1v3H0V.5A.5.5 0 0 1 .5 0H4zm8 0h3.5a.5.5 0 0 1 .5.5V4h-1V1h-3V0zM4 16H.5a.5.5 0 0 1-.5-.5V12h1v3h3v1zm8 0v-1h3v-3h1v3.5a.5.5 0
0 1-.5.5H12z"/><path fill-opacity=".256" d="M1 1h14v14H1z"/><g class="ck-icon__selected-indicator"><path d="M7 0h2v1H7V0zM0 7h1v2H0V7zm15 0h1v2h-1V7zm-8 8h2v1H7v-1z"/><path fill-opacity=".254" d="M1 1h14
v14H1z"/></g></svg>
基于此消息:
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
看起来我需要在ember中添加一些webpack加载程序,但是我真的不知道该怎么做。有人能帮忙吗?
1条答案
按热度按时间kcwpcxri1#
@ckeditor/ckeditor5-image/src/image
导入一个CSS文件。由于CKEditor使用CSS-in-JS和其他不属于ECMAScript规范的功能,您需要配置webpack以支持它。CKEditor的文档包括一个最小配置示例:Ember自动导入允许您提供自定义Webpack配置作为
autoImport.webpack
配置密钥:请联系Ember Auto Import的文档了解详细信息。
将两者结合起来,就像下面这样 * 应该 * 可行:
更新
这个方案几乎奏效了,但有几点需要注意:
正在从'@ckeditor/ckeditor 5-image/src/图像大小调整'导入
ImageResize
;“@ckeditor/ckeditor 5-build-classic”中的ClassicEditor
无法正常工作!显然这会导致重复模块错误。因此,相反,按照如何从源代码构建的说明进行操作之后,我发现ckeditor样式没有在ember中加载,直到我按照提取CSS的说明进行操作,然后一切都正常了!
以下是我的
package.json
中的相关部分:还有我的ember-cli-build.js文件:
还有我的ck-editor.js文件(我将其保存在与组件相同的目录中):
现在,从我的组件中,我可以调用: