我有一个Symfony4项目,它使用flex和encore。我想加些锡尼丝。
因此,我添加了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.我的文本区域被一个空白页所取代。
我在文档中找到了解决方案,当我将node_modules/tinymce/skins目录复制到/public/build/skins时,它工作得很好。但我还是得在每次编完纱之后再做
是否有一种方法可以自动地将这个node_modules/tinymce/skins /public/build/skins**?**目录复制到,是否可以更新webpack.config.js来完成它?
PS:我读了一些重命令和webpack-loader,但我不明白我要做什么。
发布于 2018-01-31 09:54:18
推荐:copyFiles OPTION1: buit-in 函数
使用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]'
})OPTION2 :复制webpack插件
我添加了复制webpack插件
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();发布于 2018-05-18 15:02:40
谢谢你的帖子..。它解决了我的问题,但对我来说略有不同。我不得不把皮放进去
/public/build/js/skins所以我改变了webpack的配置
.addPlugin(new CopyWebpackPlugin([
// Copy the skins from tinymce to the build/skins directory
{ from: 'node_modules/tinymce/skins', to: 'skins' },
]))至
.addPlugin(new CopyWebpackPlugin([
// Copy the skins from tinymce to the build/skins directory
{ from: 'node_modules/tinymce/skins', to: 'js/skins' },
]))而且起作用了!再次感谢!
发布于 2020-08-24 22:45:04
注意,由于复制插件的v3.11,语法发生了变化,以前的答案将不再起作用。新语法需要patterns字段:
var Encore = require('@symfony/webpack-encore');
// Plugins
var CopyWebpackPlugin = require('copy-webpack-plugin');
...
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.addPlugin(new CopyWebpackPlugin({
patterns: [
// Copy the skins from tinymce to the build/skins directory
{ from: 'node_modules/tinymce/skins', to: 'skins' },
],
}))
...https://stackoverflow.com/questions/48525861
复制相似问题