fixthestatusquo/proca

moving to craco, upgrade webpack

tttp opened this issue · 7 comments

tttp commented

the version of webpack we got form cra has been heavily modified (thanks to react-script, as wrapper allowing to inject modifications to webpack without ejecting).

However, react-script has been abandoned and we need to either eject or switch to a new system.

craco seems to be active and maintained, but the format of the overwriting config is completely different

branch feature/craco is the place I'm trying to migrate...

Oh no!

I was also looking at Rollup which seems to be pretty modern and also has an API: https://rollupjs.org/guide/en/#rolluprollup

For example, maybe we could build the bundle by passing separately such entry points:

  • src/index.js
  • any portal files
  • any journey step components
  • the config json

We would not generate src/actionPage.js as with webpack, instead we would just tell rollpack which files to add, and each of them would store the component in a global window.proca.components.Register etc; Then in src/components/Widgets.js we would read the global window.proca.config and window.proca.components.X .
Right now it's also dynamic, but uses config to read the steps variable which is imorted from actionPage.js

Actually I am not sure why we did not consider this - passing the dynamic "imports" via window and not hacking the builder to generate a "static" imports...

I mean, in each step component we can do:

window.proca.components.Share = Share;

instead of

module.exports = {Share}

Quite similar no? :P

tttp commented

When I looked at rollup, I didn't find options to build a module (proca), or to generate a single js file, but admittedly, I didn't look too long.

Some components are sometimes used directly (eg Register) or as a sub component (eg Petition or Email), how would it work?

coming back to the need: having a simple <script src=widget_name async></script> that:

  • create a global.proca that contains various functions (go, set...)
  • build the widget (equivalent of proca.go() )

build the widget has a bunch of modes:

  • put the widget where the <script> is (default)
  • put the widget where class="proca-widget" is (if exists)
  • if proca-widget contains some content, put it as a left hand column and the widget on the right hand column
  • delay the display (eg to deal with re-hydratation)
  • wait for proca.go to display (more advanced interface)

we also build the index.html page (can use different template set in the config, eg eci vs "normal") so we have a preview (convenient for demo/debug)

and a nice dev mode that automatically reloads when the code is changed.

if we could skip the webpack monstrosity and achieve all of that, it would be awesome!

Some components are sometimes used directly (eg Register) or as a sub component (eg Petition or Email), how would it work?

For sure components are just functions so you could even write <window.proca.components.Register /> as I understand it

we also build the index.html page (can use different template set in the config, eg eci vs "normal") so we have a preview (convenient for demo/debug)

Does it have to be built? (how much changes there? ) or could we just reuse one written by hand? (I am asking for case where the builder would just output Js, not JS+ html..)
As for outputs, what else do we need? map file? what else?

tttp commented
tttp commented

For sure components are just functions so you could even write <window.proca.components.Register /> as I understand it

almost: react adds a bunch of constraints on the function name (eg if should start with an uppercase), but

const Register = global.proca.component.Register would allow to <Register />.

this being said, we can probably keep both the export and the global.proca.component.xxx

tttp commented

After further tests, moved to esbuild, good feature set and magic fast