Search code examples
ruby-on-railsrubywebpackwebpacker

Integration CKEditor 4 with Rails 6 via webpack


I have to upgrade a legacy application that uses CKEdtior for the text editor features.

Since the Ruby gem for ckeditor is not so good maintained anymore and Rails 6 seems to be an issue anyway I decided to go straight with webpacker.
I added ckeditor v 4 with a yarn add command and then I am importing the js files in my application.js/active_admin.js files. (import "ckeditor4";)
According to documentation I have to set a CKEDITOR_BASEPATH constant as well. The constant should point to the path where the ckeditor files are located.
To have this files I have configured webpacker with this additional setting: environment.config.set('output.libraryTarget', 'umd')

I thought that this would create a ckeditor directory in my public/packs/js folder but it's not working. How can I make webpack create this folded/files?


Solution

  • I fixed this problem with adding the CopyPlugin and configuring it like this:

    environment.plugins.append('CopyPlugin',
        new CopyPlugin({
            patterns: [
                {
                    from: '{config.js,contents.css,styles.js,adapters/**/*,lang/**/*,plugins/**/*,skins/**/*,vendor/**/*}',
                    to: resolvePath( distPath, 'js/ckeditor' ),
                    context: resolvePath( __dirname, '../../node_modules', 'ckeditor4' )
                }
            ]
        })
    )