Javascript Can';t加载通过ember自动导入导入css的模块

Javascript Can';t加载通过ember自动导入导入css的模块,javascript,webpack,ember.js,ckeditor,Javascript,Webpack,Ember.js,Ckeditor,我正在尝试构建一个ember 3.25应用程序,通过ember自动导入导入CkEditor 通过将以下内容添加到我的包.json,我可以使编辑器正常工作: "@ckeditor/ckeditor5-build-classic": "^27.0.0", "@ckeditor/ckeditor5-adapter-ckfinder": "^27.0.0", "@ckeditor/ckeditor5-autofo

我正在尝试构建一个ember 3.25应用程序,通过
ember自动导入导入
CkEditor

通过将以下内容添加到我的
包.json
,我可以使编辑器正常工作:

"@ckeditor/ckeditor5-build-classic": "^27.0.0",
"@ckeditor/ckeditor5-adapter-ckfinder": "^27.0.0",
"@ckeditor/ckeditor5-autoformat": "^27.0.0",
"@ckeditor/ckeditor5-basic-styles": "^27.0.0",
"@ckeditor/ckeditor5-block-quote": "^27.0.0",
"@ckeditor/ckeditor5-ckfinder": "^27.0.0",
"@ckeditor/ckeditor5-cloud-services": "^27.0.0",
"@ckeditor/ckeditor5-core": "^27.0.0",
"@ckeditor/ckeditor5-dev-utils": "^24.0.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^24.4.2",
"@ckeditor/ckeditor5-easy-image": "^27.0.0",
"@ckeditor/ckeditor5-editor-classic": "^27.0.0",
"@ckeditor/ckeditor5-essentials": "^27.0.0",
"@ckeditor/ckeditor5-heading": "^27.0.0",
"@ckeditor/ckeditor5-image": "^27.0.0",
"@ckeditor/ckeditor5-indent": "^27.0.0",
"@ckeditor/ckeditor5-link": "^27.0.0",
"@ckeditor/ckeditor5-list": "^27.0.0",
"@ckeditor/ckeditor5-media-embed": "^27.0.0",
"@ckeditor/ckeditor5-paragraph": "^27.0.0",
"@ckeditor/ckeditor5-paste-from-office": "^27.0.0",
"@ckeditor/ckeditor5-table": "^27.0.0",
"@ckeditor/ckeditor5-theme-lark": "^27.0.0",
"@ckeditor/ckeditor5-typing": "^27.0.0",
"css-loader": "^5.2.2",
"mini-css-extract-plugin": "^1.5.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^3.1.0",
"style-loader": "^2.0.0"
并将以下内容添加到我的余烬组件中:

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

...

didInsertElement() {
  var editor = ClassicEditor
    .create( document.querySelector( '#editor' ), {
      ...
    });
}
import ClassicEditorBase from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import EssentialsPlugin from '@ckeditor/ckeditor5-essentials/src/essentials';
import UploadAdapterPlugin from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter';
import AutoformatPlugin from '@ckeditor/ckeditor5-autoformat/src/autoformat';
import BoldPlugin from '@ckeditor/ckeditor5-basic-styles/src/bold';
import ItalicPlugin from '@ckeditor/ckeditor5-basic-styles/src/italic';
import BlockQuotePlugin from '@ckeditor/ckeditor5-block-quote/src/blockquote';
// import EasyImagePlugin from '@ckeditor/ckeditor5-easy-image/src/easyimage';
import HeadingPlugin from '@ckeditor/ckeditor5-heading/src/heading';
import ImagePlugin from '@ckeditor/ckeditor5-image/src/image';
import ImageCaptionPlugin from '@ckeditor/ckeditor5-image/src/imagecaption';
import ImageStylePlugin from '@ckeditor/ckeditor5-image/src/imagestyle';
import ImageToolbarPlugin from '@ckeditor/ckeditor5-image/src/imagetoolbar';
import ImageUploadPlugin from '@ckeditor/ckeditor5-image/src/imageupload';
import LinkPlugin from '@ckeditor/ckeditor5-link/src/link';
import ListPlugin from '@ckeditor/ckeditor5-list/src/list';
import ParagraphPlugin from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';

export default class ClassicEditor extends ClassicEditorBase {}

ClassicEditor.builtinPlugins = [
    EssentialsPlugin,
    UploadAdapterPlugin,
    AutoformatPlugin,
    BoldPlugin,
    ItalicPlugin,
    BlockQuotePlugin,
    // EasyImagePlugin,
    HeadingPlugin,
    ImagePlugin,
    ImageCaptionPlugin,
    ImageStylePlugin,
    ImageToolbarPlugin,
    ImageUploadPlugin,
        ImageResize,
    LinkPlugin,
    ListPlugin,
    ParagraphPlugin
];

ClassicEditor.defaultConfig = {
    toolbar: {
        items: [
            'heading',
            '|',
            'bold',
            'italic',
            'link',
            'bulletedList',
            'numberedList',
            'uploadImage',
            'blockQuote',
            'undo',
            'redo'
        ]
    },
    image: {
        toolbar: [
            'imageStyle:full',
            'imageStyle:side',
            '|',
            'imageTextAlternative'
        ]
    },
    language: 'en'
};
但是当我试图通过以下方式添加
ImageResize
模块时:

"@ckeditor/ckeditor5-image": "^27.0.0",
在我的组件()中:

我最初看到的错误是:
'unhandledPromisejectionWarning:Error:webpack向ember自动导入返回了错误
,所以我运行了
auto\u import\u VERBOSE=true-ember-service

我现在看到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>

似乎我需要添加一些网页包加载器到余烬,但我真的不知道如何做到这一点。有人能帮忙吗?

@ckeditor/ckeditor 5 image/src/image
。由于CKEditor在JS中使用CSS和其他不属于ECMAScript规范的功能,您需要配置webpack以支持它。CKEditor的文档包括:

const-ckeditor-webpackplugin=require(@ckeditor/ckeditor-5-dev-webpack-plugin”);
const{styles}=require(@ckeditor/ckeditor5 dev-utils”);
module.exports={
插件:[
// ...
新的CKEditorWebpackPlugin({
//看https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
语言:“pl”,
}),
],
模块:{
规则:[
{
测试:/ckeditor5-[^/\]+[/\\]主题[/\\]图标[/\\][^/\\]+\.svg$/,,
使用:[“原始加载程序”],
},
{
测试:/ckeditor5-[^/\\]+[/\\]主题[/\\].+\.css$/,,
使用:[
{
加载器:“样式加载器”,
选项:{
injectType:“singletonStyleTag”,
属性:{
“数据cke”:正确,
},
},
},
{
加载器:“邮政编码加载器”,
选项:styles.GetPostsConfig({
themeImporter:{
主题部分:require.resolve(@ckeditor/ckeditor 5主题云雀”),
},
缩小:是的,
}),
},
],
},
],
},
};
Ember Auto Import允许您以
自动导入的方式提供自定义网页包配置。网页包
配置键:

//ember-cli-build.js
让应用程序=新应用程序(默认值{
自动导入:{
网页:{
//额外的网页包配置在这里
},
},
});
详情请联系

将这两者结合在一起应该会起作用:

//ember-cli-build.js
const ckeditor webpackplugin=require(“@ckeditor/ckeditor 5 dev webpack plugin”);
const{styles}=require('@ckeditor/ckeditor5 dev-utils');
让应用程序=新应用程序(默认值{
自动导入:{
网页:{
插件:[
新的CKEditorWebpackPlugin({
//看https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
语言:“pl”,
}),
],
模块:{
规则:[
{
测试:/ckeditor5-[^/\]+[/\\]主题[/\\]图标[/\\][^/\\]+\.svg$/,,
使用:[“原始加载程序”],
},
{
测试:/ckeditor5-[^/\\]+[/\\]主题[/\\].+\.css$/,,
使用:[
{
加载器:“样式加载器”,
选项:{
injectType:“singletonStyleTag”,
属性:{
“数据cke”:正确,
},
},
},
{
加载器:“邮政编码加载器”,
选项:styles.GetPostsConfig({
themeImporter:{
主题部分:require.resolve(
“@ckeditor/ckeditor5主题云雀”
),
},
缩小:是的,
}),
},
],
},
],
},
},
},
});
更新 此解决方案几乎有效,但有几点需要注意:

从“@ckeditor/ckeditor5 image/src/image resize”导入
ImageResize
;另外,“@ckeditor/ckeditor5 build classic”中的
ClassicEditor
也不起作用!显然,这将导致重复的模块错误

因此,相反,按照如何操作的说明进行操作之后,我发现ckeditor样式没有加载到ember中,直到我按照上的说明进行操作,然后一切都正常了

以下是我的
包.json中的相关部分:

"@ckeditor/ckeditor5-build-classic": "^27.0.0",
"@ckeditor/ckeditor5-adapter-ckfinder": "^27.0.0",
"@ckeditor/ckeditor5-autoformat": "^27.0.0",
"@ckeditor/ckeditor5-basic-styles": "^27.0.0",
"@ckeditor/ckeditor5-block-quote": "^27.0.0",
"@ckeditor/ckeditor5-ckfinder": "^27.0.0",
"@ckeditor/ckeditor5-cloud-services": "^27.0.0",
"@ckeditor/ckeditor5-core": "^27.0.0",
"@ckeditor/ckeditor5-dev-utils": "^24.0.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^24.4.2",
"@ckeditor/ckeditor5-easy-image": "^27.0.0",
"@ckeditor/ckeditor5-editor-classic": "^27.0.0",
"@ckeditor/ckeditor5-essentials": "^27.0.0",
"@ckeditor/ckeditor5-heading": "^27.0.0",
"@ckeditor/ckeditor5-image": "^27.0.0",
"@ckeditor/ckeditor5-indent": "^27.0.0",
"@ckeditor/ckeditor5-link": "^27.0.0",
"@ckeditor/ckeditor5-list": "^27.0.0",
"@ckeditor/ckeditor5-media-embed": "^27.0.0",
"@ckeditor/ckeditor5-paragraph": "^27.0.0",
"@ckeditor/ckeditor5-paste-from-office": "^27.0.0",
"@ckeditor/ckeditor5-table": "^27.0.0",
"@ckeditor/ckeditor5-theme-lark": "^27.0.0",
"@ckeditor/ckeditor5-typing": "^27.0.0",
"css-loader": "^5.2.2",
"mini-css-extract-plugin": "^1.5.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^3.1.0",
"style-loader": "^2.0.0"
和我的ember-cli-build.js文件:

  const CKEditorWebpackPlugin = require("@ckeditor/ckeditor5-dev-webpack-plugin");
  const { styles } = require("@ckeditor/ckeditor5-dev-utils");
  const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );


  module.exports = function (defaults) {
    let app = new EmberApp(defaults, {

     cssModules: {
       includeExtensionInModulePath: true,
     },

      sassOptions: {
       inputFiles: [  
         '/app/styles/app.scss',  
        ],
        includePaths: ['app', 'app/components']
      },
      // Add options here
      autoImport: {
        webpack: {
          plugins: [
           new CKEditorWebpackPlugin({
              // See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
              // language: "en",
            }),
            new MiniCssExtractPlugin( {
              filename: 'ckeditor.css'
            } )
          ],
          module: {
            rules: [
              {
                test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
                use: ["raw-loader"],
              },
              {
                test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
                use: [
                  MiniCssExtractPlugin.loader,
                  'css-loader',
                  {
                    loader: "postcss-loader",
                    options: styles.getPostCssConfig({
                    themeImporter: {
                      themePath: require.resolve(
                        "@ckeditor/ckeditor5-theme-lark"
                      ),
                    },
                    minify: true,
                  }),
                },
              ],
            },
          ],
        },
      },
    },
  });


  return app.toTree();
};
和我的ck-editor.js文件(与我的组件保存在同一目录中):

现在,从我的组件中,我可以调用:

import ClassicEditor from './ck-editor';

...

didInsertElement() {
  var editor = ClassicEditor
    .create( document.querySelector( '#editor' ), {
      ...
    });
}

非常感谢你!这确实帮助我走上了正确的道路。我要对你的答案做一些修改,现在我已经让它工作了!