Apologies for a slightly long post. To be quite honest I’m totally over my head here.
I have been spoiled by frameworks like Quasar into never needing to learn how webpack works/is set up - until now:
I am trying to add CKEditor to my project, a WYSIWYG that supports Vue, but unfortunately it requires you to configure/chain webpack through vue.config.js (The docs assume that you have built your project using the Vue CLI). I understand vaguely that quasar is performing a lot of what vue.config does under the hood, but I don’t know enough about Webpack to debug my efforts or know if I’m on the right track.
Assuming that this is even possible, I am attempting to convert the vue.config.js instructions that they provide in their docs to something that meshes with quasar.conf
Here is their config:
module.exports = {
// The source of CKEditor is encapsulated in ES6 modules. By default, the code
// from the node_modules directory is not transpiled, so you must explicitly tell
// the CLI tools to transpile JavaScript files in all ckeditor5-* modules.
transpileDependencies: [
/ckeditor5-[^/\]+[/\]src[/\].+\.js$/,
],
configureWebpack: {
plugins: [
// CKEditor needs its own plugin to be built using webpack.
new CKEditorWebpackPlugin( {
// See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
language: 'en'
} )
]
},
css: {
loaderOptions: {
// Various modules in the CKEditor source code import .css files.
// These files must be transpiled using PostCSS in order to load properly.
postcss: styles.getPostCssConfig( {
themeImporter: {
themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
},
minify: true
} )
}
},
chainWebpack: config => {
// Vue CLI would normally use its own loader to load .svg files. The icons used by
// CKEditor should be loaded using raw-loader instead.
// Get the default rule for *.svg files.
const svgRule = config.module.rule( 'svg' );
// Then you can either:
//
// * clear all loaders for existing 'svg' rule:
//
// svgRule.uses.clear();
//
// * or exclude ckeditor directory from node_modules:
svgRule.exclude.add( __dirname + '/node_modules/@ckeditor' );
// Add an entry for *.svg files belonging to CKEditor. You can either:
//
// * modify the existing 'svg' rule:
//
// svgRule.use( 'raw-loader' ).loader( 'raw-loader' );
//
// * or add a new one:
config.module
.rule( 'cke-svg' )
.test( /ckeditor5-[^/\]+[/\]theme[/\]icons[/\][^/\]+\.svg$/ )
.use( 'raw-loader' )
.loader( 'raw-loader' );
}
};
Here is what I have so far in quasar.conf:
build: {
scopeHoisting: true,
vueRouterMode: "hash", // available values: 'hash', 'history'
showProgress: true,
gzip: false,
analyze: false,
transpile: true,
transpileDependencies: [
/ckeditor5-[^/\]+[/\]src[/\].+\.js$/,
],
// Options below are automatically set depending on the env, set them if you want to override
// preloadChunks: false,
extractCSS: true,
// https://quasar.dev/quasar-cli/cli-documentation/handling-webpack
extendWebpack(cfg) {
cfg.plugins.push(new CKEditorWebpackPlugin( {
// The UI language. Language codes follow the https://en.wikipedia.org/wiki/ISO_639-1 format.
language: 'en'
} ))
},
chainWebpack(chain, { isServer, isClient }) {
const svgRule = chain.module.rule( 'svg' );
svgRule.exclude.add( __dirname + '/node_modules/@ckeditor' );
chain.module
.rule( 'cke-svg' )
.test( /ckeditor5-[^/\]+[/\]theme[/\]icons[/\][^/\]+\.svg$/ )
.use( 'raw-loader' )
.loader( 'raw-loader' );
}
},
The missing piece:
css: {
loaderOptions: {
// Various modules in the CKEditor source code import .css files.
// These files must be transpiled using PostCSS in order to load properly.
postcss: styles.getPostCssConfig( {
themeImporter: {
themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
},
minify: true
} )
}
}
From reading the docs, it seems like maybe Quasar handles this through .postcssrc.js, although I have no idea how to structure that file.
In general, does it look like I’m on the right track? Any ideas about how to handle that CSS section?
The error I’m getting atm when rendering the component ‘Cannot read property ‘getAttribute’ of null’ appears to be related to how SVG is being loaded through webpack, but of course out of context this probably doesn’t mean too much, and the stack trace isn’t too helpful when the issue is with webpack.
And if anyone out there has any experience working with CKEditor + Quasar I’d love to hear about it. Still evaluating if it’s worth the effort.