how to include cropperjs library in rails6 using the webpacker - javascript

I want to add the cropper functionality using the data modal, but I could not even select the file from the data modal.
I tried using the yarn install command and webpacker but javascript is not adding to the corresponding page.

Add the cropperjs using yarn's add command and then import your necessary functions from the node_modules you have installed. Also, include CSS files from the node_modules, otherwise there might be some issues related to the styling.

Related

Import local JS files into Meteor

I'm having terrible problems when trying to import an external JS project into my meteor folder. This is the project I'll like to use: http://www.outsharked.com/imagemapster/default.aspx?demos.html#beatles
As you can see, it is necessary to import two scripts. The first one is JQuery, and that was easily solved by adding it with meteor add jquery.
The problem came out when I tried to import the second script. I'm not sure how I can use it because, as far as I know, on meteor you cannot just import your script into the head section. For that reason, I've created a new template that is rendered and I put the code in there, but nothing happenend. Later on I've created an event that calls the JS when the image is clicked but without any success.
My question is, Which is the correct way to import a local JS code in meteor as in HTML is done with:
<script type="text/javascript" src="../dist/jquery.imagemapster.js"></script>
Since jquery-imagemapster is available as an npm package you can do:
$ npm install jquery-imagemapster
In your project directory and make it available to your project that way.
In early versions of Meteor packages were only available via atmosphere and $ meteor add. Later they added npm support and all npm packages became available.
Prefix npm installs with “meteor” -> “meteor npm install —save ‘js file’. Initializing will be the same as it would be in any other front end environment as will importing it. If you’re having trouble after that, check for it’s existance in your browser console and work from there using its built in properties and methods.

Edit an existing cordova plugin

I want to change just a single line in an installed cordova plugin.
However, as the plugin is installed via package.json, any edit I do
on the source file does not get saved as the plugin is freshly
installed every time I make a new build of my app.
Is there some way to:
Copy-paste the whole plugin somewhere outside the plugins folder so I can edit without it getting overwritten.
Remove the plugin name from package.json and
Be able to reference the plugin inside my app so I can use the methods provided by the plugin.
Thank You.
You can clone the plugin and make the changes you want locally. Then you can add the plugin using corodova plugin add /path/to/plugin/folder.

Add canvasjs library that does not exist in bower to my project

I would like to use CanvasJS library in my project but it does not exist in bower packages, so I tried to install it from a local zip file that I downloaded from their website. After successful installation the bower.json file includes the library's version and local path
"canvasjs-1.9.8": "C:\\path\\to\\myfolder\\canvasjs-1.9.8.zip"
Then if I try to build the project using gulp (e.g gulp serve), the library is not automatically added in the of index.html, as it happens for all the other libraries.
Is it a problem that it was installed from a local file? Is there another way to add CanvasJS library to my project and to my index.html file which is automatically generated with gulp build?
Thank you.
You can use gulp-inject in order to automatically inject code inside your index for example. Here the link:
https://www.npmjs.com/package/gulp-inject
So you can manually download your library (please include the .js version not the .zip), put it inside your project and dynamically include it inside the index using that plugin, adding a new task inside your gulp serve/build process.
You can also think to provide support for the library in the bower repository. It will make it available through bower to you and to the other users too in the future, if they may need it.
If you want to create a bower package, please refer to the official documentation that is really well done:
https://bower.io/docs/creating-packages/
For the bower installation I followed the instructions of this answer, and I assumed that using the .zip file that I downloaded would work. Since it didn't, the solution was to unistall it, un-compress the zip file and install the local .js file of the library. Then gulp serve command included the library in the index.html.

Bootstrap Touch Carousel with Webpack

I am in the process of moving a legacy webapp over to run on some sort of frontend dependancy manager. In this instance im using Webpack and NPM.
I have been able to migrate 90% of the app over, however I am stuck on an issue with bootstrap-touch-carousel.
It seems even though I have installed it via npm, I am still not able to call it via the normal require(./bootstrap-touch-carousel).
Are the some dependencies that need to be required differently? Or am I on the wrong track?
You cannot import it with require('bootstrap-touch-carousel') because in this module package.json there isn't main file
You must explicitly import distributed .js file by doing this:
require('bootstrap-touch-carousel/dist/js/bootstrap-touch-carousel')

Using Leaflet with plugin in Meteor

I'm building an app with Meteor 1.3, and I need Leaflet and leaflet-measure. I've installed both with NPM, and import them to my file with import. I have a simple template with a map-div, and a corresponding JS-file with a onRendered-callback. It creates my Leaflet-map and it works.
The problem starts when trying to add Leaflet-measure:
Using NPM and importing tells me that a method in fs is missing, but installing and importing that as well does not help.
I've tried adding the dist-files to a lib-folder in client and importing them, but I get an error that indicates that the code hasn't been run:
How can I make a plugin like this work with Meteor?

Categories

Resources