My website is based on Wordpress and I am using multiple plugins for my purpose. For some reason I need to modify one of my existing plugins and want to add SweetAlert2 based alert message.
For that I need to install SweetAlert package using command "npm install sweetalert2". But I am not sure where to run this command.
The folder structure of Wordpress based website is like this :
~/public_html/wp-content/plugins/
I need to show sweetalert based alert messages from the plugin named 'myCustomPlugin'.
Do I need to run 'nmp install' command within 'wp-content' folder or within the specific plugin folder or in some other folder ?
For a production based website is it sufficient to run just "npm install sweetalert2" command to use it ? Some other links also say to use "npm install --save sweetalert2".
I am bit confused what to run and where to run.
Thanks!!
CodePudding user response:
Ordinarily you put Javascript code into a plugin by putting it into a file named something like
.../wp-content/plugins/mycustomplugin/js/sweetalert2.all.min.js
You then get your plugin to put it into your HTML by calling wp_enqueue_script().
This library has zero dependencies, so it doesn't need a build step. Unless your plugin is a Gutenberg editor custom block there's no need to use npm. All you need is a copy of the Javascript code in your plugin directory.