webpack SplitChunk not working while using a specific NPM package - reactjs

I'm using a NPM package in my project that has a lot of dependencies but all of them imported dynamically and also some of them lazy loaded, but when I import that package in my React project and bundle my project, all the dependencies and sources of that package comes to my app bundle, I also tried to use webpack SplitChunk but it doesn't help me and just create separate file for that package and all the dependencies of that package will load on first load.
Anyone has an idea what should I do? Due to I just import a package I don't know what source code should I share here but if you need any, comment it please.

Related

Why Typescript is not recognizing min.js and .js import?

Hi I am trying to import some js file of a installed dashboard in a typescript file of React app. But it is not working, Below I have added a screenshot of the imports and error.
Please help:
The error msg tells you precisely what to do:
npm i --save-dev #types/adminbsb-materialdesign
In order for typescript to work with external libraries you need to import type definitions (*.d.ts) for them. --save-dev makes the package available in dev time only.

How to setup bootstrap-material-design react for theme overwrite

I am looking to start a new react project and I was hopeful about using bootstrap-material-design but I'm not sure how to setup the project to overwrite the theme. The documentation talks about adding custom sass but I am not familiar with sass. I was hoping someone knew what step you need to get this working. I've created a fresh react app with npx create-react-app and installed the package with npm via npm install bootstrap-material-design#4.1.1. I've also added a scss folder at the root level of the project with a custom.scss file in that folder. currently the only code added to that file is an import of their sass files with #import "node_modules/bootstrap/scss/bootstrap"; but nothing seems to happen when I add a material design component such as a Navbar. I also import the custom.scss file in the index.js file with import './scss/custom.scss'; but I am still getting the following error: File to import not found or unreadable: ../../node_modules/bootstrap/scss/bootstrap.
I guess my question is has anyone successfully used this package in a react project by using npm to install rather than using the cdn and if so can they tell me the steps require to get this up and running so I can re-theme bootstrap-material-design with my own branding.
Thanks!
Install required package
npm install bootstrap-material-design node-sass
Add SASS path
open .env, add following magic
SASS_PATH=node_modules:src or SASS_PATH=./node_modules;./src for windows
Rename App.css to App.scss
Open App.scss
Add following code: #import 'bootstrap-material-design/scss/bootstrap-material-design.scss';
So far work for me.

React Package is not getting loaded from node-modules

I have created the package for learning purpose nik-drop presently available in npm.
now testing purpose I tried to use that package in my another demo project but when I try to use this package from npm-moduls. I unable to access that package.
Even through Package is available in node-module folder.
import DropDownMob from 'nik-drop';
I'm getting error
Module not found: Can't resolve 'nik-drop' in '/home/nikhil/Documents/React-Project/sec/sec/src'
This is not node module path, react trying to access it from local directory.
How can I resolve it.

How to use Storybook components (and Lerna) in an external project done with Next.js?

I've just created my Storybook library of components (ES6 etc).
It is structured as a Lerna project (all components isolated in the packages/ folder). However, that's a private repo with no real publish feature so, I think Lerna won't work with a private (free) account.
I've pushed the storybook repo to my Bitbucket as it is.
Now, I'd like to use my storybook library of components from the main application which is a different repo (on Bitbucket) build on Next.js.
I was attempting to import the individual storybook components as follows
import MyComponent from 'storybook-repo/packages/my-component/my-component';
but it obviously doesn't work, returning this error:
Module parse failed: Unexpected token (8:9)
You may need an appropriate loader to handle this file type.
This, because MyComponent is a jsx file.
I was hoping Next.js to transpile the imported modules but this is not the case.
My questions are:
My guts say the import of the whole storybook as git+ssh://git#bitbucket.org/myusername/storybook-repo.git from package.json is not a good idea. Any better solutions?
Is it true that Lerna works only for public/Pro repos where I can publish my packages?
Why is Next.js not transpiling the imported jsx modules? At this point, how does this process work? Shall I transpile the storybook components from the remote repo or do the job from my main application?
Thanks
On my last project, we used Rollup.js to create a dist build of just the components we had developed in Storybook. Our components were located in src/components directory. We maintained an index.js for the components using an internal scaffolding tool. We published our dist folder as a privately scoped NPM package and then pulled in our components from there.
For local development, we used Webpack aliasing to check the current environment and either pull the published NPM package or pull directly from the storybook/dist folder that we were building to.
There's a great guide on building this here. Hope this points you in the right direction. As an alternative, I believe you can fiddle with next.config.js to override the Webpack config and make sure that your external imports get sucked up through the same Webpack, but, you also have to add a few rules to the .babelrc on the Storybook side to ensure that it gets ignored over there. We found it to be easier to just publish a package and bundle everything up.

REACT QRCODE: Unable to import module [cirocosta/qcode-decoder]

I am working on a React Web App which requires a QR Code Scanner,
I imported the package QCodeDecoder through npm, still when I did import QCodeDecoder from 'qcode-decoder';
it throws an error that the module not found. I checked in the npm_modules and it is there.
I think qcode-decoder is not an npm package. I see it contains a package.json but the file they are using as main doesn't exist.
In the documentation they claim the package should be installed through bower so you might need to give it a try that way.

Resources