错误尝试使用WebPack Encore使用Tinymce插件

发布于 2025-02-10 03:42:03 字数 1370 浏览 1 评论 0原文

我正在尝试在Textarea元素上使用Tinymce插件:

<textarea id="reportDescription" name="reportDescription" class="form-control" rows="4"></textarea>

IM与Symfony和WebPack Encore一起工作。 安装了软件包

yarn add tinymce

因此,我使用:在我编码的WebPack.config.js中

.copyFiles({
        from: 'node_modules/tinymce/skins',
        to: 'skins/[path]/[name].[ext]'
    })

:在我尝试初始化插件的.js中:

require('tinymce');

$(document).ready(function () {
   
    if($("#reportDescription").length > 0){
        tinymce.init({
            selector: "textarea#reportDescription"
            
        });
    }
});

当我将页面加载到浏览器上时,我会收到此错误:

tinymce.js:4680 
    GET http://url/build/models/dom/model.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load model: dom from url models/dom/model.js
tinymce.js:4680 
    GET http://url/build/icons/default/icons.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load icons: default from url http://url/build/icons/default/icons.js
tinymce.js:4680 
    GET http://url/build/themes/silver/theme.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load theme: silver from url themes/silver/theme.js

我不明白很好,但是如何在WebPack上使用模块。如何导入它们,何时使用或导入以及它们之间的差异。所以也许我错过了一些重要的东西。

I'm trying to use the Tinymce plugin on a textarea element:

<textarea id="reportDescription" name="reportDescription" class="form-control" rows="4"></textarea>

Im working with Symfony and Webpack Encore. So I installed the package using:

yarn add tinymce

In webpack.config.js I coded:

.copyFiles({
        from: 'node_modules/tinymce/skins',
        to: 'skins/[path]/[name].[ext]'
    })

And in the .js where I'm trying to initialize the plugin:

require('tinymce');

$(document).ready(function () {
   
    if($("#reportDescription").length > 0){
        tinymce.init({
            selector: "textarea#reportDescription"
            
        });
    }
});

When I load my page on my browser, I get this error:

tinymce.js:4680 
    GET http://url/build/models/dom/model.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load model: dom from url models/dom/model.js
tinymce.js:4680 
    GET http://url/build/icons/default/icons.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load icons: default from url http://url/build/icons/default/icons.js
tinymce.js:4680 
    GET http://url/build/themes/silver/theme.js net::ERR_ABORTED 404 (Not Found)
tinymce.js:18181 
    Failed to load theme: silver from url themes/silver/theme.js

I don't understand very well yet how to work with modules on webpack. How to import them, when to use require or import and the difference between them. So maybe I'm missing something important.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福还没到 2025-02-17 03:42:03

我拥有的设置如下

  1. 安装复制WebPack插件 - YARN添加copy-webpack-plugin -dev

  2. in webpack.config.js

      const copyplugin = require(“ copy-webpack-plugin”); //顶部
    // ...
    // ...其他东西
    
    encore.addplugin(
     新的copyplugin({
         模式:[[
           {
             上下文:'./node_modules/tinymce/',
             来自:'**/*。(min.js | min.css | woff)',
             至:'./ tinymce/ [path] [name] [ext]'
           }
         这是给出的
       }))
     );
    
    encore
       //将存储资产的目录
       .setOutputPath('public/build/')
       //其他代码
     
  3. i中使用刺激器,因此在刺激控制器(tiny_controller.js)中,我有下面的代码,以便所有带有Tinymce类的Textareas都将匹配

     来自“@hotwired/stimulus”的导入{Controller};
     从“ Tinymce/tinymce”中导入Tinymce;
     //其他代码
     //其他代码
     初始化(){
         this.defaults = {
             base_url:'/build/tinymce',
             插件:“预览Importcss”,
             Menubar:“查看插入格式工具表”,
             工具栏:'撤消重做|大胆的斜体'
             Toolbar_sticky:false,
             后缀:'.min'
         };
     }   
    
     连接() {
         this.inittinymce();
     }
    
     Inittinymce(){
         令config = object.sign({{
             选择器:“ textarea.tinymce”,
         },this.defaults);
         tinymce.init(config);
     }
     //其他代码
     //其他代码
     

这可能是这样的。

<div data-controller="tiny">
    <textarea name="comment" class="tinymce">Enter text here..</textarea> 
</div>

the set up I have is as follows

  1. install copy webpack plugin -- yarn add copy-webpack-plugin --dev

  2. In webpack.config.js

    const CopyPlugin = require("copy-webpack-plugin");  // at the top
    // ...
    // ... other stuff
    
    Encore.addPlugin(
     new CopyPlugin({
         patterns: [
           {
             context: './node_modules/tinymce/',
             from: '**/*.(min.js|min.css|woff)',
             to: './tinymce/[path][name][ext]'
           }
         ]
       })
     );
    
    Encore
       // directory where compiled assets will be stored
       .setOutputPath('public/build/')
       // other code
    
  3. I use stimulusjs so in the stimulus controller (tiny_controller.js) I have the code below so that all textareas with tinymce class will be matched

     import { Controller } from "@hotwired/stimulus";
     import tinymce from 'tinymce/tinymce';
     // other code
     // other code
     initialize() {
         this.defaults = {
             base_url: '/build/tinymce',
             plugins: 'preview importcss',
             menubar: 'view insert format tools table',
             toolbar: 'undo redo | bold italic'
             toolbar_sticky: false,
             suffix: '.min'
         };
     }   
    
     connect() {
         this.initTinyMCE();
     }
    
     initTinyMCE() {
         let config = Object.assign({
             selector: 'textarea.tinymce',
         }, this.defaults);
         tinymce.init(config);
     }
     //other code
     //other code
    

Finally in the HTML Form it could be something like this

<div data-controller="tiny">
    <textarea name="comment" class="tinymce">Enter text here..</textarea> 
</div>
友欢 2025-02-17 03:42:03

尽管@patrick kenekayoro发布了一个非常不错的答案,但在您的情况下,问题是路径。您可以注意到,它在寻找/build/models /...,因此要解决此此简单/粘贴以下代码到您的WebPack配置:

.copyFiles({
    from: 'node_modules/tinymce/skins',
    to: 'skins/[path]/[name].[ext]'
})

.copyFiles({
    from: 'node_modules/tinymce/models',
    to: 'models/[path]/[name].[ext]'
})

.copyFiles({
    from: 'node_modules/tinymce/plugins',
    to: 'plugins/[path][name].[ext]',
    includeSubdirectories: true,
    pattern: /.*/
})

.copyFiles({
    from: 'node_modules/tinymce/icons',
    to: 'icons/[path][name].[ext]',
    includeSubdirectories: true,
    pattern: /.*/
})

即使在最新的中,这对我也很好符号项目。

Whilst @Patrick Kenekayoro posted a really nice answer, in your scenario the issue is the path. As you can notice, it looks for /build/models/..., so to resolve this simply copy/paste the below code to your webpack config:

.copyFiles({
    from: 'node_modules/tinymce/skins',
    to: 'skins/[path]/[name].[ext]'
})

.copyFiles({
    from: 'node_modules/tinymce/models',
    to: 'models/[path]/[name].[ext]'
})

.copyFiles({
    from: 'node_modules/tinymce/plugins',
    to: 'plugins/[path][name].[ext]',
    includeSubdirectories: true,
    pattern: /.*/
})

.copyFiles({
    from: 'node_modules/tinymce/icons',
    to: 'icons/[path][name].[ext]',
    includeSubdirectories: true,
    pattern: /.*/
})

This worked for me really well even in the latest Symfony projects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文