Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKEditor5 custom build problem #393

Closed
devgogo opened this issue Sep 30, 2018 · 4 comments
Closed

CKEditor5 custom build problem #393

devgogo opened this issue Sep 30, 2018 · 4 comments
Labels

Comments

@devgogo
Copy link

devgogo commented Sep 30, 2018

I follow this example: https://ckeditor.com/docs/ckeditor5/latest/framework/guides/quick-start.html

// webpack.config.js

const {styles} = require('@ckeditor/ckeditor5-dev-utils');
//...
.addLoader({
        test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
        loader: 'raw-loader'
})
.addLoader({
        test: /ckeditor5-[^/]+\/theme\/[\w-/]+\.css$/,
        use: [
            {
                loader: 'postcss-loader',
                options: styles.getPostCssConfig({
                    themeImporter: {
                        themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
                    },
                    minify: true
                })
            },
        ]
    })

Then an error occurred. How can I solve it?

Thx.

screen shot 2018-09-30 at 9 15 01 am

@galvesband
Copy link

galvesband commented Oct 7, 2018

Hi. I've dealt with something similar but i'm a noob in the webpack and modern javascript world so take this with a grain of salt.

I've updated my symfony4 project to encore#master, by the way. I don't know if it is the same with the last stable version.

I think your problem is that the svg icons from ckeditor5 are not being handled correctly becouse rules fight each other for them. My solution disables encore default image loaders and set up new ones excluding ckeditor svg assets.

const {styles} = require('@ckeditor/ckeditor5-dev-utils');
// ...
Encore.
  // ...
  .addPlugin(new CKEditorWebpackPlugin({
    // .. CKEditor options like language and stuf...
  }))
  // Disable default image loaders from encore
  ..disableImagesLoader()
  // Use raw-loader for CKEditor icons only
  .addRule({
        test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
        use: [ {
            loader: 'raw-loader'
        } ]
    })
  // Next one is pretty much the default encore rule for handling images but excluding CKEditor
  .addRule({
        test: /\.(svg|png|jpg|jpeg|gif|ico)/,
        exclude: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
        use: [{
            loader: 'file-loader',
            options: {
                filename: 'images/[name].[hash:8].[ext]',
                publicPath: '/build/'
            }
        }]
    })
  .addRule({
        test: /\.css$/,
        use: [
            {
                loader: 'postcss-loader',
                options: styles.getPostCssConfig( {
                    themeImporter: {
                        themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
                    },
                    minify: true
                } )
            },
        ]
    });

Hope it helps

@Lyrkan
Copy link
Collaborator

Lyrkan commented Oct 7, 2018

Hi,

The postcss-loader part can also probably be handled by Encore.enablePostCssLoader (I didn't test it though):

Encore.enablePostCssLoader(options => {
    Object.assign(options, styles.getPostCssConfig({
        themeImporter: {
            themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
        },
        minify: true // Not sure that's needed, the css-loader already minifies CSS
    }));
});

@galvesband
Copy link

galvesband commented Oct 7, 2018

@Lyrkan I've tested it and you are right, removing the post-css loader rule and using your snippet works well in my setup. minify is indeed not needed.

Thank you.

@Lyrkan Lyrkan added the question label Oct 7, 2018
@Kocal
Copy link
Contributor

Kocal commented Aug 12, 2019

Hi, today I had to build CKEditor5 from source in order to use the Underline plugin.

There is actually no documentation that shows how to do it (I'm planning to open an issue/PR on CKEditor docs repo see ckeditor/ckeditor5#1956), so I made a repo that describe how to: https://github.com/Kocal/webpack-encore-vue-ckeditor5

(The configureLoaderRule is really useful! 😝 👀 )

I think this issue can be closed.

EDIT: Instead of using enablePostCssLoader() and configure it, we can use the following code to add a new postcss-loader for CKEditor5 only, and prevent issues with other .css if you work on an application which build CKEditor5:

When using .enablePostCssLoader():
Sélection_999(138)

Use this instead:

  Encore.addLoader({
    test: /ckeditor5-[^/\\]+[/\\].+\.css$/,
    loader: 'postcss-loader',
    options: styles.getPostCssConfig({
      themeImporter: {
        themePath: require.resolve('@ckeditor/ckeditor5-theme-lark'),
      },
    }),
  })

@devgogo devgogo closed this as completed Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants