gpt4 book ai didi

symfony - 如何将Tinymce与Symfony encore集成?

转载 作者:行者123 更新时间:2023-12-04 22:18:31 35 4
gpt4 key购买 nike

我有一个使用 flex encore Symfony4 项目。我要添加tinymce。

因此,我添加了tinymce项目:

$ yarn add tinymce

我编辑了 app.js文件:
require('../css/app.scss');

// Import TinyMCE
import tinymce from 'tinymce/tinymce';

// A theme is also required
import 'tinymce/themes/modern/theme';

// Any plugins you want to use has to be imported
import 'tinymce/plugins/paste';
import 'tinymce/plugins/link';

// Initialize the app
tinymce.init({
selector: 'textarea',

plugins: ['paste', 'link']
});

我编译了:
$ yarn run encore dev

编译成功:
Running webpack ...

DONE Compiled successfully in 17600ms

I 8 files written to public\build
Done in 20.23s.

我的textareas替换为空白页。

我在 documentation中找到了解决方案,当我将 node_modules/tinymce/skins目录复制到 /public/build/skins时,它可以正常工作。但是每次 yarn 编译后我仍然必须这样做

是否可以自动将此node_modules/tinymce/skins目录复制到/public/build/skins是否可以更新 webpack.config.js来做到这一点?

PS:我读了一些 webpack-loaderrecommandations,但是我不知道该怎么做。

最佳答案

选项1:推荐:内置copyFiles函数
使用Encore的内置copyFiles函数。

var Encore = require('@symfony/webpack-encore');

//...

Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')

// copy tinymce's skin files
.copyFiles({
from: 'node_modules/tinymce/skins',
to: 'skins/[path]/[name].[ext]'
})
Encore's API reference
选项2:复制Webpack插件
我添加了 copy webpack plugin
yarn add copy-webpack-plugin --dev
我编辑了webpack.config.js仅添加了4行:
var Encore = require('@symfony/webpack-encore');

//DECLARATION OF THE NEW PLUGIN
var CopyWebpackPlugin = require('copy-webpack-plugin');

Encore
// the project directory where all compiled assets will be stored
.setOutputPath('public/build/')

// the public path used by the web server to access the previous directory
.setPublicPath('/build')

// will create public/build/admin/app.js and public/build/admin/app.css
.addEntry('admin', './assets/js/app.js')

//Some project lines
//...
//...

//I call the plugin with its new syntax (since 3.11)
.addPlugin(new CopyWebpackPlugin({
patterns: [
// Copy the skins from tinymce to the build/skins directory
{ from: 'node_modules/tinymce/skins', to: 'skins' },
],
}))

//Some project lines
//...
//...
;

// export the final configuration
module.exports = Encore.getWebpackConfig();

关于symfony - 如何将Tinymce与Symfony encore集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525861/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com