loadable-components | The recommended Code Splitting library for React ✂️✨ | Server Side Rendering library
kandi X-RAY | loadable-components Summary
kandi X-RAY | loadable-components Summary
Loadable Components is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to the support of these awesome backers. If you'd like to join them, please consider:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a new component instance .
- Resolve a component .
- transform a call to Imports
- Replaces a chunk
- Generate a source node for a module node .
- Convert an asset stream into a inline element .
- Return inline style in an asset file .
- Initialize the application .
- Returns the value of call to a given call .
- Represents a component .
loadable-components Key Features
loadable-components Examples and Code Snippets
Loadable.preloadAll().then(() => {
app.listen(3000, () => {
console.log('Running on http://localhost:3000/');
});
});
Community Discussions
Trending Discussions on loadable-components
QUESTION
ANSWER
Answered 2022-Feb-14 at 19:18CSS modules in Gatsby v3 onwards needs to be imported as ES modules, so your:
QUESTION
I recently implemented serverside-rendering react app with code splitting using loadable-components
But it seems that loadable-components itself dependent on webpack, since loadable replaces jsonp_callback with its own reporter.
So what are the alternative options that we can use when using other bundlers like rollup, esbuild?
Do we have to manually walk through the react tree to pre configure which chunk is needed on which component unless there is no specific bundler targeted library like loadable-components when implementing code splitting on serverside rendering?
...ANSWER
Answered 2021-Oct-18 at 05:13Is tsconfig typeRoots unnecessary?
First, let us consult the compiler options reference:
The documentation for typeRoots
states (emphasis mine):
By default all visible
@types
packages are included in your compilation. Packages innode_modules/@types
of any enclosing folder are considered visible. For example, that means packages within./node_modules/@types/
,../node_modules/@types/
,../../node_modules/@types/
, and so on.
If
typeRoots
is specified, only packages undertypeRoots
will be included.
That second line is important: if you don't set typeRoots
then tsc defaults to looking for directories under node_modules
containing @types
in their directory names.
(The documentation doesn't say if it chooses node_modules
because of the moduleResolution
parameter though. (I suspect I'd need to dig-in tsc
's source-code to find out for sure).)
If you do set a value for typeRoots
than that overrides tsc's node_modules/**/@types*
lookup logic and it will then only look in the specified directories.
As I know, I have to specify the path of the above file into
typeRoots
option oftsconfig
file sincetypeRoots
defaults to look into thenode_modules/@types
.
Not necessarily. You could also add your extra typings files' locations to the paths
parameter and leave the typeRoots
parameter blank/un-set, which means tsc
will retain the "node_modules/@types
-and-ancestor-walking behavior" but will see your .d.ts
files just fine.
This scenario is mentioned in this TypeScript GitHub thread: https://github.com/microsoft/TypeScript/issues/13581
So if you're asking about your specific local environment on your machine: and assuming that you're sticking with the normative, typical (I dare say mainstream) TypeScript working idioms (such as using npm
) then yes: you can remove the typeRoots
parameter because tsc
's (current) default behavior is to look for node_modules
directories in the same location as your tsconfig.json
.
(I understand that VS Code might also be pulling some strings behind-the-scenes to make tsc
"aware" of your project files and dependencies and for its language-server process - but that shouldn't matter as you'll notice tsc
should work identically from the command-line outside of VS Code).
If you're asking about the fundamental necessity of the typeRoots
compiler option, and supposing that you're thinking "that because practically everyone is using npm
and node_modules
then why is the TypeScript team spending their time supporting unusual development configurations?"_ - well, for many very good reasons: tools shouldn't be dependent on other tools controlled by third-parties1: Consider the possibility that the npm
ecosystem and/or NodeJS software could fall out of fashion overnight and then we'd be stuck with tsc
's defaults still using node_modules
when everyone is rockin' some new cool JS environment: there'd be headaches for many years to resolve the mess (not that the JS ecosystem isn't a mess as it is).
And there are many good reasons to not use npm
and node_modules
: people could be using TypeScript in an environment without internet access (think: secure software development, the defence industry, national secrets, etc) - those people in those situations might have a network share full of approved or known-trustworthy libraries that won't be using node_modules
's naming convention - in which case if those people want to use d.ts
files they'll need to manually configure the typeRoots
parameter for themselves.
1 I'm aware that npm
(which is legally separate from NodeJS, btw) is maintained by npm Inc, which is a subsidary of Microsoft (by way of being acquired by GitHub, also a Microsoft property), so having tsc
depend on npm
shouldn't be a problem - but that's a very recent thing: Microsoft only acquired npm
18 months ago in March 2020 - and Microsoft could very well spin-off npm Inc - or run it into the ground and everyone switches to yarn
. So regardless of the end legal owners of whatever tooling is currently popular, you don't want unnecessary dependencies like that.
QUESTION
I have run gatsby clean
before npm run develop
but still it has not made a difference...
My gatsby-node.js file has been looked at by others who are familiar with the Gatsby framework, and they're not sure what the problem is either...
Here is my gatsby-node.js file:
...ANSWER
Answered 2021-Sep-30 at 07:58Try running gatsby clean first, and then try it again…
QUESTION
I am using Gatsby to build static site and keycloak for auth.
I am using these libs: keycloak-js
and @react-keycloak/web
During development (gatsby develop) everything runs fine, auth works and all that...
But when i run gatsby build
, it fails specifically with this error:
WebpackError: authClient has not been assigned to ReactKeycloakProvider
This is the react keycloak lib that i am using @react-keycloak/web and error comes from useKeycloak.ts
file.
ANSWER
Answered 2021-Mar-09 at 18:43Have you tried loadable-components
? It seems a matter of SSR...
QUESTION
I have a JSON file with several filepaths to scripts that I want to be able to load dynamically into my React app, to build each component based on specifications that are in the metadata. Currently I have the metadata in my app as a Metadata
data object.
metadata.json:
...ANSWER
Answered 2021-Mar-09 at 03:06You don't need @loadable/component
for two reasons.
- You can accomplish your goal with dynamic imports
- '@loadable/component' returns a React Component object, not your function.
To use dynamic imports simply parse your JSON the way you were, but push the call to the import's default function into state
. Then all you have to do is render the "layers" from within the state.
Like this:
QUESTION
I'm running a number of Gatsby sites from a monorepo and use gatsby-plugin-loadable-components-ssr to display different widgets (components) on different sites. When looking at the production bundle though, there's a reference to each available widgets' file path even if they are not being used at the current page.
As I'm thinking of expanding my widget configuration setup into a basic page builder I'm going to be looking at adding a large number of new widgets and would therefore very much prefer if the bundle wasn't bloated with references to unused components.
Has anyone successfully achieved something like this?
...ANSWER
Answered 2020-Aug-27 at 09:15You'll want to try out the WIP work done here: https://github.com/gatsbyjs/gatsby/pull/24903 (Issue: https://github.com/gatsbyjs/gatsby/issues/18689). This will be the way forward to programmatically import components / have the desired code-splitting.
QUESTION
I've got a p5.js
sketch that is included in my gatsby.js
project. When I push and build my project on netlify.com
it thows:
error "window" is not available during server side rendering.
- on:
window.requestAnimationFrame = (function() {
WebpackError: ReferenceError: window is not defined
Ok, I understand why. During the build the window DOM is not available. So I tried to work around it with two ways, as seen in my code example.
- First is to use react loadable componant
- Second to check if
window
is undefined (on build) and if so return something else than the main code.
my code example:
...ANSWER
Answered 2020-Feb-28 at 08:56I finally figured it out. I've switched from react-p5-wrapper to react-p5. It kept giving problems, even with the solution. So I switched. Also I've moved the check if window exists into the component. Which is much cleaner
QUESTION
History: I recently discovered an odd behaviour with using Webpack and dynamic imports. First I thought it might be the 3rd-party library 'Loadable Components' I used, so I opened a bug issue (https://github.com/gregberge/loadable-components/issues/517) on their end. The author replied telling me that the behaviour is coming from Webpack and the dynamic imports themselves.
I can stand the fact that it does not tree-shake the dynamic import, for me it is more important to understand why that is the case.
Demo repository to demonstrate the behaviour can be found here: https://github.com/dazlious/treeshaking-dynamic-imports
Short description of the problem: From my perspective, an imported named export should not force all the exported code to be bundled within it.
In the demo case we have a component (./lib/index.jsx) that has two sub components called module1 (./lib/module1/module1.jsx) and module2 (./lib/module1/module2.jsx). Module1 exports a constant called FOO_BAR that is then imported by Module2 as a named import.
When looking at the build output, you'll find Module2 containing Module1 in whole and not only the string that is specifically imported.
Is anyone with deep knowledge of Webpack and/or dynamic imports around here? Would be happy to learn more about the behaviour.
...ANSWER
Answered 2020-Feb-03 at 13:51I edited the webpack.config to be:
QUESTION
I'm using the library @loadable/component with react routes, for code splitting etc.
...ANSWER
Answered 2020-Jan-08 at 10:18You can put if
inside render()
function, for example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install loadable-components
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page