小编Mil*_*lls的帖子

稍微修改 resourceRegExp 时 NormalModuleReplacementPlugin 不起作用

正如CKEditor5主页上的官方建议,我想替换几个插件预装的标准图标。由于每个插件(例如 ckeditor5-core 或 ckeditor5-alignment).svg在 [PLUGIN_DIR]/theme/icons 中都提供了自己的设置,因此建议的策略 - 用自己的修改替换它们 - 是可以理解和明确的:

(...) 使用 webpack 的 NormalModuleReplacementPlugin 插件

...
plugins: [
  new webpack.NormalModuleReplacementPlugin(
    /bold\.svg/,
    '/absolute/path/to/my/icon.svg'
  )
]
Run Code Online (Sandbox Code Playgroud)

基于此代码,我进行了试验并最终得到了以下结果:

...
plugins: [
  new webpack.NormalModuleReplacementPlugin(
    /\/theme\/icons\/[^/]+\.svg$/,
    resource => {
      console.log(resource.request);
      resource.request = path.resolve(
        THEME_PATH,
        "../../icons/coffee-solid.svg"
      );
    }
  ),
]
Run Code Online (Sandbox Code Playgroud)

导致以下(想要的/预期的)变化: before after

部分控制台输出:

../../theme/icons/bold.svg
../../theme/icons/italic.svg
@ckeditor/ckeditor5-core/theme/icons/quote.svg
@ckeditor/ckeditor5-core/theme/icons/image.svg
../theme/icons/numberedlist.svg
../theme/icons/bulletedlist.svg
../theme/icons/align-justify.svg
../theme/icons/link.svg
(node:10394) DeprecationWarning: Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead
@ckeditor/ckeditor5-core/theme/icons/object-right.svg
@ckeditor/ckeditor5-core/theme/icons/object-center.svg
@ckeditor/ckeditor5-core/theme/icons/object-left.svg
@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg
@ckeditor/ckeditor5-core/theme/icons/low-vision.svg
../theme/icons/drag-handler.svg
@ckeditor/ckeditor5-core/theme/icons/cancel.svg
../theme/icons/redo.svg
../../../theme/icons/next-arrow.svg
../../../theme/icons/previous-arrow.svg
../theme/icons/undo.svg
../../../theme/icons/dropdown-arrow.svg …
Run Code Online (Sandbox Code Playgroud)

icons theming ckeditor webpack

1
推荐指数
1
解决办法
1563
查看次数

标签 统计

ckeditor ×1

icons ×1

theming ×1

webpack ×1