-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get TinyMCE to work with webpack and babel #2836
Comments
We are going to look into improving webpack/browserify support. We really want people to be able to stitch together their own editor using the parts. Thanks for sharing these details. |
Thanks @hkjorgensen this works perfectly! 👍 @spocke this would be really great if we have proper support. |
Ah, this works awesome! This is exactly what I needed |
Thanks for sharing! |
@hkjorgensen Thanks for sharing this, what about browserify? |
Some plugins like imagetools don't work and I guess they need other files to be imported in bundle. If I don't use these plugins everything works fine. |
Thanks a lot! |
Has anyone figured out how to set content_css using webpack? |
One possible solution is to use ExtractTextPlugin so the CSS is actually bundled into a CSS file that you can later import into Only caveat I see is that you loose Hot Module Replacement for CSS. |
Thanks @hkjorgensen for sharing! Works great (though I'm skipping the babel-part, just using regular require()'s). However I can't seem to get the paste-plugin to work for me. 😢 Commenting out the require of the paste-plugin gets core tinymce work like a charm, though. |
@ChrisJons same issue with using any plugins and themes for me. Also not sure how you add in additional tinymce themes using npm. I have had to use tinymce as a global due to these issues. |
I found that the loader test didn't work on Windows, this regex seems to be more compatible.
|
I'm getting these errors:
Don't know more what to do, I think I'll give up and use the cdn. |
@victorpfm Make sure you are importing all the plugins, themes and skins you're using as well. I found it best to use the file loader to include the skin styles / fonts in the output folder so they were available for the stylesheet manager to import at runtime. I did this by using
Then in my
Unfortunately with this approach you have to exclude the tinymce/skins folder from every other loader. I'm sure there's a better approach if I dug deeper.
|
@phdesign If you only use the file loader for the tinymce/skins folder it might be easiest to skip the require.context(
'file?name=[path][name].[ext]&context=node_modules/tinymce!tinymce/skins',
true,
/.*/
) Then you shouldn't have to exclude the tinymce/skins folder from all the other loaders, right? 🤔 |
Doesn't work with webpack and Angular2 typescript as described here If I use
after transpiled by typescript
If I change it to |
@IAMtheIAM Does it work if you use |
@fyrkant Where do we put the:
I have been trying to get tinymce to function with webpack, but none of the css is functioning. (It correctly finds the field, and initializes, but no css is showing / rendering. (It just makes a blank space.) |
@hkjorgensen Thanks for the post. But if I import tinymce from the tinymce folder it does not work.
It says it can't find module. Adjusted your example to point at my node_modules folder. |
To show how to put the tips in this thread together I made a simple lite example app here. |
@fyrkant Thanks for the great workaround with require.context(
'!file?name=[path][name].[ext]&context=node_modules/tinymce!tinymce/skins',
true,
/.*/
) In this case webpack emit the actual content of CSS files instead of JS wrapping |
@jarrettj you shouldn't require npm packages with a relative path, you should use the |
Have issue with skin styles bleed over to global style scope (body). import 'tinymce/skins/lightgray/skin.min.css'
import 'tinymce/skins/lightgray/content.min.css' With following webpack config related part: ...
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
... And as a result the lightgray skin applied its styles globally when it suppose to be only tinymce sandboxed iframe. What the less cumbersome way to address this issue? I might missing something obvious and doing it wrong way though... UPD: Figured it out thanks for @fyrkant and @Darkside73 posts above. |
is there a way to import all plugins in one line from tinymce ? |
@foodaka No there is no way to import all plugins, and it really isn't something I would recommend doing either. Just importing the plugins you need will keep your bundle as small as possible. |
Is there a solution to it right now? I do not get any errors, but still my component do not render it correctly. I don't see the element with the eye, it's invisible and in the element inspector all the classes are added... |
I used the approach listed in tinymce document: https://www.tinymce.com/docs/advanced/usage-with-module-loaders/#gettingtheskin. It works but the consumer of my bundle has to specify the url to the skin folder via the config because tinymce skin manager looks for skins folder under root and in my single page application the root is not where the output js bundle and skins folder are. Would it be possible to bundle all resources file along with the js files into a single file? It seems unrealistic because the skin manager of tinymce dynamically loads skin files. I am asking in case I missed anything. |
This comment worked for me perfectly well, with Webpack 2: #2836 (comment). Together with skins and everything. |
@lakesare thanks! that's how I am doing it now, but it's not bundling the css inline with the js files. What I wanted is a single js file that contains everything. |
Does anyone have an example of how to use In addition when using the |
@aneurysmjs Is this problem solved? |
good job |
Did anyone solved this for webpack > 3.5.5 ? |
Has someone fixed the issue reported by @ssilve1989 in this comment? |
This post was a huge help. I just spend hours trying to figure out why Tinymce was almost working, but not quite. Adding the imports for all the plugins was what I was missing. |
I just wanted to add my solution for a custom skin here because I couldn't find a simple explanation and this is working for me plus our webpack setup is a little complex. We made a custom skin using http://skin.tiny.cloud/ Then I manually copy the whole folder to a different location, we also use different relative paths so I ended up doing something like this: webpack.config.js additions:
Then the Tiny MCE part:
Hope that helps some people who are also stick on this. |
For those looking to bundle the skin and/or content CSS, this can be achieved with a combo of webpack.config.js rules: [
{
test: /\.css$/,
use: ['css-loader']
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader'
}
] import tinymce from "tinymce/tinymce";
import "style-loader!tinymce/skins/lightgray/skin.min.css";
import contentStyle from "tinymce/skins/lightgray/content.min.css";
tinymce.init({
skin: false,
content_style: contentStyle.toString()
}); |
thanks @ryanerato |
@ryanerato, I just tried your approach, and it's still not working for me. I'm using TinyMCE5, and Symfony's WebpackEncore bundler system. Below are the affected lines of my config: webpack.config.js
my separate js module responsible for returning default configs:
And I'm getting the following errors in browser's console: However it seems like TinyMCE gets initialized properly but the errors annoys me anyway. Thanks in advance! |
It works with TinyMCE5 and webpack4. // Import TinyMCE
import 'tinymce/tinymce';
// A theme is also required
import 'tinymce/themes/silver';
import 'tinymce/skins/ui/oxide/skin.css';
// Any plugins you want to use has to be imported
import 'tinymce/plugins/advlist';
import 'tinymce/plugins/autolink';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/link';
import 'tinymce/plugins/image';
import 'tinymce/plugins/charmap';
import 'tinymce/plugins/print';
import 'tinymce/plugins/preview';
import 'tinymce/plugins/anchor';
import 'tinymce/plugins/searchreplace';
import 'tinymce/plugins/visualblocks';
import 'tinymce/plugins/code';
import 'tinymce/plugins/fullscreen';
import 'tinymce/plugins/insertdatetime';
import 'tinymce/plugins/media';
import 'tinymce/plugins/table';
import 'tinymce/plugins/paste';
import 'tinymce/plugins/help';
import 'tinymce/plugins/wordcount';
import contentStyle from '!!raw-loader!tinymce/skins/ui/oxide/content.css';
import contentStyle2 from '!!raw-loader!tinymce/skins/content/default/content.css';
import Editor from '@tinymce/tinymce-vue';
export default {
extends: Editor,
props: {
init: {
type: Object,
default() {
return {
skin: false,
content_css: false,
content_style: contentStyle.toString() + '\n' + contentStyle2.toString(),
};
},
},
},
}; |
Got me working with react:
|
Hi zhangsanshi, Can you share the webpack.config.js about TinyMCE?
I fellow the TinyMCE's document, here is my config: module:
rules: [
{
test: /skin\.css$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader'],
},
{
test: /content\.css$/i,
use: ['css-loader'],
},
]
....
optimization: {
splitChunks: {
chunks: 'all',
minSize: 30000,
minChunks: 1,
maxAsyncRequests: 6,
maxInitialRequests: 3,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
chunks: 'all',
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
tinymceVendor: {
chunks: 'all',
test: /[\\/]node_modules[\\/](tinymce)[\\/](.*js|.*skin.css)|[\\/]plugins[\\/]/,
name: 'tinymce',
priority: 20,
},
vue: {
name: 'vue',
test: /vue/,
priority: 10,
chunks: 'all'
}
},
}
}, |
I have a couple of projects that uses TinyMCE and I think it's one of the better editors when HTML is the document model.
I wanted to use TinyMCE with a webpack setup so I tried:
npm i --save tinymce
and thenimport tinymce from 'tinymce'
- but that didn't work.After some time researching I got a solution to work. I just want to share it here if it can help others with the same issue. A couple of people have already asked for it.
This is not an issue but just a simple guide to get up and running :-)
Requirements
A working webpack setup with Babel (es2015 presets)
Dependencies
You need tinymce and a couple of loaders for webpack.
Webpack config
Use
window
asthis
in the wrapping function generated by webpackImplementation
Create a file in your source and add the following:
I've added
skin: false
because I assume the project want to use it's own pipeline to provide the CSS as a bundle. TinyMCE won't work until the CSS is included(!)The text was updated successfully, but these errors were encountered: