question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CKEditor 5 SVGs do not build properly

See original GitHub issue
  • Laravel Mix Version: 1.7.2
  • Node Version: v8.9.4
  • NPM Version: 5.6.0
  • Yarn Version: 1.3.2
  • OS: Fedora release 27

Description:

I am attempting to use the new CKEditor 5 Framework with Mix. As described in the CKEditor Quick Start Guide I have imported CKEditor libs into app.js (and removed everything else) then I built the file. The results seem to show the SVGs are not loaded properly and the icons in the editor toolbar are missing.

https://screenshots.firefox.com/LEYu0SnGQVMaew0E/127.0.0.1

I also receive this error output in the console.

XML Parsing Error: not well-formed
Location: http://127.0.0.1:8000/
Line Number 1, Column 1:
127.0.0.1:8000:1:1

I then attempted to fix the svg loader issue with the webpack config recommended on the guide.

mix.js('resources/assets/js/app.js', 'public/js').webpackConfig({
  module: {
    rules: [{
      test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,

      use: ['raw-loader']

    }]
  }
});

It produces the same result. I also tried the full webpack config:

mix.js('resources/assets/js/app.js', 'public/js').webpackConfig({
  module: {
    rules: [{
      test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,

      use: ['raw-loader']

    }, {
      test: /ckeditor5-[^/]+\/theme\/[^/]+\.scss$/,

      use: [
        'style-loader',
        'css-loader',
        'sass-loader'
      ]
    }]
  }
});

But I get errors:

ERROR  Failed to compile with 1 errors                                                                                                                                                                    17:29:16

 error  in ./node_modules/@ckeditor/ckeditor5-editor-classic/theme/theme.scss

Module build failed: 
// Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
^
      Invalid CSS after "...load the styles": expected 1 selector or at-rule, was "var content = requi"
      in /home/ryan/Sites/ckeditortesting/node_modules/@ckeditor/ckeditor5-editor-classic/theme/theme.scss (line 1, column 1)

 @ ./node_modules/@ckeditor/ckeditor5-editor-classic/theme/theme.scss 4:14-198
 @ ./node_modules/@ckeditor/ckeditor5-editor-classic/src/classiceditor.js
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js

Here is the app.js

// app.js
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ Essentials, Paragraph, Bold, Italic ],
        toolbar: [ 'bold', 'italic' ]
    } )
    .then( editor => {
        console.log( 'Editor was initialized', editor );
    } )
    .catch( error => {
        console.error( error.stack );
    } );

Without the custom webpack configurations mix says the SVGs are exported. I’m not sure where they are being exported.

 DONE  Compiled successfully in 2812ms                                                                                                                                                                     17:39:08

                                                                                                Asset       Size  Chunks                    Chunk Names
          fonts/vendor/@ckeditor/ckeditor5-undo/theme/icons/undo.svg?2753736cbcf3b2effb8d48c0814062a9  233 bytes          [emitted]         
          fonts/vendor/@ckeditor/ckeditor5-undo/theme/icons/redo.svg?8ea320f1905146e40376ea5ff82ef1c8  234 bytes          [emitted]         
  fonts/vendor/@ckeditor/ckeditor5-basic-styles/theme/icons/bold.svg?436104cc4191810a16da276b12d62720    1.14 kB          [emitted]         
fonts/vendor/@ckeditor/ckeditor5-basic-styles/theme/icons/italic.svg?42697e1fe4701d27b907ce418d5266dc  663 bytes          [emitted]         
                                                                                           /js/app.js    1.97 MB       0  [emitted]  [big]  /js/app
Done in 4.47s.

Steps To Reproduce:

  1. Create a new Laravel Project
  2. Add CKEditor via yarn/npm
yarn && yarn add \@ckeditor/ckeditor5-editor-classic \
    @ckeditor/ckeditor5-essentials \
    @ckeditor/ckeditor5-paragraph \
    @ckeditor/ckeditor5-basic-styles
  1. Add the previous app.js and build the js with yarn dev
  2. Set the welcome.blade.php file to the following:
<!doctype html>
<html lang="{{ app()->getLocale() }}">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>Laravel</title>

  <!-- Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
</head>

<body>
  <div id="editor">
    <p>Editor content goes here.</p>
  </div>

  <script src="js/app.js"></script>
</body>

</html>
  1. Load the project homepage.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
hanreevcommented, Aug 15, 2018

Here’s how i ended up overriding the default laravel-mix to correctly compile CKEditor5 without modifying it

  • Removed all --config=node_modules/laravel-mix/setup/webpack.config.js in package.json scripts
  • Then imported laravel-mix default config and override in webpack.config.js
const defaultConfig = require('laravel-mix/setup/webpack.config.js')
const { styles } = require('@ckeditor/ckeditor5-dev-utils')

const ckeditor5_pattern = {
  svg: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
  css: /ckeditor5-[^/]+\/theme\/[\w-/]+\.css$/,
}

defaultConfig.module.rules.map(rule => {
  for (let key in ckeditor5_pattern) {
    if (`test.${key}`.match(rule.test)) {
      if (rule.exclude) {
        if (rule.exclude instanceof Array)
          rule.exclude.push(ckeditor5_pattern[key])
        else
          rule.exclude = [rule.exclude, ckeditor5_pattern[key]]
      } else
        rule.exclude = ckeditor5_pattern[key]
    }
  }

  return rule
})

const rules = [
  {
    test: ckeditor5_pattern['svg'],
    use: [ 'raw-loader' ]
  },
  {
    test: ckeditor5_pattern['css'],
    use: [
      {
        loader: 'style-loader',
        options: {
          singleton: true
        }
      },
      {
        loader: 'postcss-loader',
        options: styles.getPostCssConfig( {
          themeImporter: {
            themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
          },
          minify: true
        } )
      },
    ]
  }
]

defaultConfig.module.rules = defaultConfig.module.rules.concat(rules)

module.exports = defaultConfig

1reaction
Temu4commented, Jul 26, 2019

Here’s how i ended up overriding the default laravel-mix to correctly compile CKEditor5 without modifying it

  • Removed all --config=node_modules/laravel-mix/setup/webpack.config.js in package.json scripts
  • Then imported laravel-mix default config and override in webpack.config.js
const defaultConfig = require('laravel-mix/setup/webpack.config.js')
const { styles } = require('@ckeditor/ckeditor5-dev-utils')

const ckeditor5_pattern = {
  svg: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
  css: /ckeditor5-[^/]+\/theme\/[\w-/]+\.css$/,
}

defaultConfig.module.rules.map(rule => {
  for (let key in ckeditor5_pattern) {
    if (`test.${key}`.match(rule.test)) {
      if (rule.exclude) {
        if (rule.exclude instanceof Array)
          rule.exclude.push(ckeditor5_pattern[key])
        else
          rule.exclude = [rule.exclude, ckeditor5_pattern[key]]
      } else
        rule.exclude = ckeditor5_pattern[key]
    }
  }

  return rule
})

const rules = [
  {
    test: ckeditor5_pattern['svg'],
    use: [ 'raw-loader' ]
  },
  {
    test: ckeditor5_pattern['css'],
    use: [
      {
        loader: 'style-loader',
        options: {
          singleton: true
        }
      },
      {
        loader: 'postcss-loader',
        options: styles.getPostCssConfig( {
          themeImporter: {
            themePath: require.resolve('@ckeditor/ckeditor5-theme-lark')
          },
          minify: true
        } )
      },
    ]
  }
]

defaultConfig.module.rules = defaultConfig.module.rules.concat(rules)

module.exports = defaultConfig

@hanreev thank you a lot! )

Read more comments on GitHub >

github_iconTop Results From Across the Web

CKEditor 5 SVGs do not build properly · Issue #1397 - GitHub
I am attempting to use the new CKEditor 5 Framework with Mix. As described in the CKEditor Quick Start Guide I have imported...
Read more >
Integrating from source - CKEditor 5 Documentation
Learn how to install, integrate and configure CKEditor 5 Builds and how to work with CKEditor 5 Framework, customize it, create your own...
Read more >
CKEditor 5 v15.0.0 with horizontal line and SVG upload support
We are happy to announce the release of CKEditor 5 v15.0.0. This editor version introduces support for inserting horizontal lines, ...
Read more >
Development environment - CKEditor 5 Documentation
Learn how to install, integrate and configure CKEditor 5 Builds and how to work with CKEditor 5 Framework, customize it, create your own...
Read more >
Vue.js 2.x component - CKEditor 5 Documentation
# Configuring vue.config.js ... To build CKEditor with your application, certain changes must be made to the default project configuration. ... By default,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found