react-summernote: Cannot configure Webpack
In the installation instruction, configuration of Webpack is included:
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
Since manual Webpack configuration is not allowed in create-react-app boilerplate of Facebook, I tried using…
import $ from "jquery"
window.$ = $;
window.jQuery = $;
instead.
Yet still, dropdowns of buttons in the toolbar are not working. Any idea/solution for this?
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 17
There is an easier way to solve this problem. Create a js file to include your globals
//globals.js import jquery from 'jquery'; window.jQuery = jquery; window.jquery = jquery; window.$ = jquery;then in your component js file
import "../globals"; import ReactSummernote from 'react-summernote'; import 'react-summernote/dist/react-summernote.css';If you used
create-react-appand ejected, this is what I did:Installed
bootstrap3andjquery:npm i bootstrap3npm i jqueryThen, edit your
webpack.config.js, add the following (I placed mine as the last item inplugins, right above the closing].filter(Boolean),for plugins… add this code:new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" }),Where ever you use
react-summernotecomponent, I did the following (based on @Deewai suggestion). Add the imports at top:import jquery from 'jquery';import 'bootstrap3/js/modal';import 'bootstrap3/js/dropdown';import 'bootstrap3/js/tooltip';import 'bootstrap3/dist/css/bootstrap.css';AFTER all imports but before your function or class declaration, put the following:
window.jQuery = jquery;window.jquery = jquery;window.$ = jquery;This allowed for
react-summernotereact to work for me.Hope that helps.
I solved this by manually using bootstrap js files and jQuery. Since the problematic dropdown button generated by summernote has the class name of “dropdown-toggle”, I inserted…
import $ from "jquery";import bootstrap/js/dropdown";and,
$(".dropdown-toggle").dropdown();insiderender()I also noticed that dropdown won’t still work unless a re-render occurs after an action is called. In my case, initialization of form made the trick.