Next.js project with Rollup
Unanswered
Golden paper wasp posted this in #help-forum
Golden paper waspOP
I have a project where I want to include an additional js module on the page that gets executed when loading in the browser. At the moment I have it working as a static js file in /public but that's not really a good solution.
I've used rollup before to do this kind of thing so my question is how:
1. How might I get rollup added or to replace webpack?
Or alternatively
2. How can I get webpack to do this?
Some notes:
1. The module is meant to run in the browser so including it normally through a page or component causes build failures
2. I have tried converting it to react-ish components with
I've used rollup before to do this kind of thing so my question is how:
1. How might I get rollup added or to replace webpack?
Or alternatively
2. How can I get webpack to do this?
Some notes:
1. The module is meant to run in the browser so including it normally through a page or component causes build failures
2. I have tried converting it to react-ish components with
useEffect however this doesn't work well as Hydration takes long to run and results in the script being invoked multiple times (on every Hydration pass)22 Replies
Golden paper waspOP
Transitive interactivity stuff, probably other things later
There is a cycling carocel that cycles between pages every minute and clicking on the tabs switches to the appropriate page.
And context menus where clicking on the button toggles the contents and clicking anywhere on the page hides them.
This is done by having delegated event listeners at the document level.
document.addEventListener('click', e => {
const toggler = e.target.closest('[data-toggle]');
if (toggler) {
const target = e.target.closest(toggler.dataset.toggleTarget);
if (target) {
target.classList.toggle(toggler.dataset.toggle);
}
}
});
document.addEventListener('click', e => {
if (e.target.closest('.dropdown-toggle')) {
return;
}
const openContainers = document.querySelectorAll('.dropdown-container.open');
if (openContainers.length) {
if (!e.target.closest('.dropdown-container.open')) {
// close open dropdowns instead of doing whatever the click would have done
e.preventDefault();
e.stopPropagation();
}
openContainers.forEach(i => i.classList.remove('open'));
}
}, { capture: true });Golden paper waspOP
I'm aware it's probably not the "correct" way React would want to do it
I'm trying to make it fully server components
@Golden paper wasp I'm trying to make it fully server components
well that doesnt change anything cause the interactivity is still the same and will even suffer cause your js that u have doesn't fall into the optimisations of react
Golden paper waspOP
I tried adding it as a component but it forced the use of
'use client;yeah correct
Golden paper waspOP
So I'm not really sure what other way there is
@Golden paper wasp So I'm not really sure what other way there is
this is the only way
listeners are clientside only
Golden paper waspOP
At my current scale, React has a bigger impact on performance than my couple events.
The way I see it, I would rather have one bind run once at page load than multiple on every navigation since load.
I just want to know how I can apply a bundler to it so I can have it minified/commonjs-ified and combined from smaller files.