How to use existing libraries in reactjs/webpack like GSAP? - reactjs

I want to use existing library like GSAP. I am using webpack, though I don't know what is the right way to do this. Should I be using bower to install my packages and injecting them into my index.html where there are the js and css injection points as if I had used grunt? Or should I be npm installing packages?

You have to use npm package installation and you have to use like
npm install --save GSAP
it will also update your package.json file.

Related

Cannot find module "node-sass" react

I am trying to build react app and I want to use scss to style my app.
Challenge is that even though I already installed node-sass, but I still get this error.
./src/styles/styles.scss (/usr/local/lib/node_modules/react-scripts/node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!/usr/local/lib/node_modules/react-scripts/node_modules/postcss-loader/src??postcss!/usr/local/lib/node_modules/react-scripts/node_modules/resolve-url-loader??ref--6-oneOf-5-3!/usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/styles/styles.scss)
To import Sass files, you first need to install node-sass.
Run `npm install node-sass` or `yarn add node-sass` inside your workspace.
Require stack:
- /usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/getDefaultSassImplementation.js
- /usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/getSassImplementation.js
- /usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/index.js
- /usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js
- /usr/local/lib/node_modules/react-scripts/node_modules/loader-runner/lib/loadLoader.js
- /usr/local/lib/node_modules/react-scripts/node_modules/loader-runner/lib/LoaderRunner.js
- /usr/local/lib/node_modules/react-scripts/node_modules/webpack/lib/NormalModule.js
- /usr/local/lib/node_modules/react-scripts/node_modules/webpack/lib/NormalModuleFactory.js
- /usr/local/lib/node_modules/react-scripts/node_modules/webpack/lib/Compiler.js
- /usr/local/lib/node_modules/react-scripts/node_modules/webpack/lib/webpack.js
- /usr/local/lib/node_modules/react-scripts/scripts/start.js
I also tried to delete node_modules and reinstalled node-sass but it didn't work. Any advice?
This happens to me sometimes and seems like issue with npm. Try installing node-sass using yarn
yarn add node-sass
I'm not going to answer this question directly!
But point to an important matter! node-sass is deprecated!
sass package is used now in react-scripts. And the whole sass compiler or pre-processor is followed in the Dart sass project!
sass package is a distribution of Dart sass!
You can check more details and illustration in the following answer:
https://stackoverflow.com/a/68327656/7668448
This really seems like issue with npm (it happend not always), but if you already use npm to your project, it would be better to use:
npm cache clear --force
instead of relocating all dependencies on yarn.

Where do the html, css and other files go after converting angular project to npm module and how is a project converted to npm module?

I want to customize ngx-material-timepicker node module by changing basic html and css of the project. But no html, css files are available in the node_modules-> ngx-material-timepicker folder only ts files are there.
So I forked it to my github repo and then after customizing it, I tried installing it to my angular project by using npm install mygitrepo.git --save but after this i cannot include the module to my angular project.
In a default npm install, the registry is set to https://registry.npmjs.org/. This is where npm will download packages from when you run npm install .
You can Modify the value of the repo location to a custom repo with the command npm set registry . After resetting the registry, npm will only fetch packages from instead.
But you may not want to change the registry entirely. You can also use a organization specific scope to place your packages to be fetched.
https://docs.npmjs.com/about-scopes
Here is a short blog on publishing a module in general. https://hackernoon.com/publish-your-own-npm-package-946b19df577e

How should I include aws-appsync in AngularJS project

I am working on a AngularJS project that uses bower as package manager and gulp to inject the dependencies into the index.html file. I am not very familiar with both of these tools.
I now want to use AWS AppSync, but it is not available as a bower package.
Currently the AWS SDK is specified as a file dependency in bower.json as:
"aws-sdk": "./thirdparty/script/aws-sdk-2.69.0.min.js",
When I install aws-appsync with npm npm install aws-appsync the node_modules folder for aws-appsync contains multiple js files in the lib directory.
How can I include these with bower or is there another way to do this altogether?
I am currently unable to change much of the build and dependency management process so any suggestions working with the current tools would be much appreciated.
Thanks for reaching out!
The Bower team itself has recommended that people migrate to npm or yarn, and so aws-appsync has not been pushed to Bower.
It might be worth investigating whether you can install directly from github using something like...
bower install <github url>.git
... and install directly from the appsync-sdk github repo.
In the end I hacked together an interim solution until I can move the whole project over to npm and browserify.
I added the aws-appsync package using npm and required it in a new file. This file is then passed through a gulp task that uses the browserify plugin. The added file is then included into the rest of the build process as before.

Uninstall unused dependencies via bower

I have created an AngularJS application utilising the SB Admin 2 layout. I installed it via Bower, which also installed a lot of dependencies such as Flot.js and others. My question is, I don't use any of this extra libraries, how can I remove this unnecessary libraries?
command to uninstall a bower package
bower uninstall library-name
use --save to remove the same as a dependency from bower.json
bower uninstall library-name --save
Before uninstalling, Make sure that you have removed the respective module as a dependency in your angular application.

Adding new dependencies to yeoman angular-fullstack project

I have started working on a new project in node js and I have generated the project using yeoman's angular fullstack generator. And now I would like to add a new bower dependency and a new node dependency. What is the best way to do this? Should I simply add the dependency in bower.json and package.json or should I run a specific command?
You don't need yeoman to install those dependancies for you. Instead, yeoman gives you an environment with everything set up to use tihngs like bower, npm, grunt etc. You can add additional dependencies like you normally would using npm or bower.
for bower (http://bower.io/) -
bower install -S <name-of-your-dependancy>
that command downloads the code for you, and it also adds a reference to it in your bower.json
similar for node (https://www.npmjs.com/) -
npm install -S <name-of-your-dependancy>
use npm packet manager, to install components, like if you want to install cordova, use:
npm install -g cordova
For installing AngularJs, follow the official site guide lines:
https://docs.angularjs.org/misc/started

Resources