You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 6+Webpacker+Stimulus环境下TinyMCE图标加载404求助

Fixing TinyMCE Icons 404 Error in Rails 6 + Webpacker + Stimulus

Yep, that 404 error is definitely because Webpacker isn't bundling TinyMCE's default icon resources, so it's trying to load them from an incorrect path. You've got two straightforward fixes here—I'd recommend the first one for simplicity:

Method 1: Directly Import the Default Icons Module

This is the cleanest approach, since TinyMCE's default icons are packaged as a standalone module. Just add one line to your Stimulus controller's imports:

import tinymce from 'tinymce/tinymce';
import 'tinymce/themes/silver';
import 'tinymce/skins/ui/oxide/skin.min.css';
import 'tinymce/icons/default'; // Add this line to import default icons
// Your other plugin imports go here...

Once you add this import, Webpack will automatically bundle the icon module into your pack files, and TinyMCE will load the icons without any extra path configuration. No need to tweak your tinymce.init() settings beyond what you already have (like skin: false).

Method 2: Use require.context for Icon Resources

If the first method doesn't work for some reason (e.g., a specific version quirk), you can explicitly tell Webpack to bundle the icon files using require.context, similar to how you handled the skin resources. Add this to your controller's connect method:

connect() {
  // Existing skin context code
  const skinContext = require.context(
    '!file-loader?name=[path][name].[ext]&context=node_modules/tinymce/skins',
    true,
    /\.(png|jpg|jpeg|gif|svg|css|js)$/
  );
  skinContext.keys().forEach(skinContext);

  // New icon context code
  const iconsContext = require.context(
    '!file-loader?name=[path][name].[ext]&context=node_modules/tinymce/icons',
    true,
    /icons\.js$/
  );
  iconsContext.keys().forEach(iconsContext);

  // Initialize TinyMCE as before
  tinymce.init({
    selector: `#${this.element.id}`,
    skin: false,
    // Your other config options...
  });
}

This uses file-loader to copy the icon JS files into your packs directory, so TinyMCE can find them at the correct path when it tries to load them.

Just double-check that you aren't overriding the icons option in your tinymce.init() config—by default, icons: 'default' will work once the module is bundled correctly.

内容的提问来源于stack exchange,提问作者phil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 20:03:14