question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Discussion] Global API and ecosystem

See original GitHub issue

Hello,

As we’re starting again from scratch, it would be a good time to think about the API we want to provide to rewired CRA consumers.

I’d like customize-cra to take a more functional approach so we just have to import a bunch of addThing(), provide their specifics options, and we’re good to go! 🚀

This is what I have in mind :

// fantasy organization xD
const { override } = require('@react-app-rewired/core')
const addReactHotLoader = require('@react-app-rewired/add-react-hot-loader')
const addEmotion = require('@react-app-rewired/add-emotion')
const addBundleVisualizer= require('@react-app-rewired/add-bundle-visualizer')

module.exports = override(
  addReactHotLoader , /* no options */
  addEmotion(), /* can have options, here none given so falling back to emotion's defaults */
  addBundleVisualizer({ reportFilename: 'bundle.html' })
)

The override function is an helper providing the (config, env) to all the functions in the pipeline.

The addX functions have to respect two criterias :

  • Take their specific options and return a function accepting (config, [env]). If they don’t have any options then you can just write the (config, [env]) directly.
  • Always return the altered config object.

And that’s it!

The implementation of override is :

const { flow, curry } = require('lodash')

function override(...pipeline) {
  return function(config, env) {
    return flow(
      ...pipeline.map(f => {
        const curried = curry(f, 2)
        return curried(curry.placeholder, env)
      })
    )(config)
  }
}

And here is an example of “addX” library for webpack-bundle-visualizer :

const { /* re-exported from lodash for convenience */ merge } = require('@react-app-rewired/core')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

module.exports = function addBundleVisualizer(options) {
  const defaultOptions = {
    analyzerMode: 'static',
    reportFilename: 'report.html'
  }
  return function(config) {
    config.plugins.push(
      new BundleAnalyzerPlugin(merge(defaultOptions, options))
    )
    return config
  }
}

Also, installing @react-app-rewired/core would be enough to get started with the scripts in package.json (either we include react-app-rewired or we restart from scratch…)

What do you think? 💡

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:36 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
jgouxcommented, Oct 3, 2018

@arackaf FP is especially hard in JS because it’s not strongly typed. Doing FP in Haskell or PureScript is a joy because you just need to connect the types! 😍

2reactions
timarneycommented, Oct 3, 2018

Now I’m wondering what was the reasoning for introducing the env parameter in react-app-rewired? (maybe @timarney can answer here)

In practice I don’t think env is used much and yes it’s just process.env.NODE_ENV

I would remove (if I was writing that code again).

https://github.com/timarney/react-app-rewired/blob/master/packages/react-app-rewired/scripts/start.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Driving Marketplace with API Ecosystem and Open Banking
The bi-directional data flow enabled through API banking now ... Panel Discussion | Driving Marketplace with API Ecosystem and Open Banking.
Read more >
(PDF) Visualizing the Maturing Global API Ecosystem
This study focuses on the global API ecosystem guided by two assumptions: 1) geographic proximity is distorted, and the global API ecosystem ......
Read more >
API Strategy: Engaging the ecosystem
The answer lies in the API ecosystem, which encourages API providers and consumers to collaborate in order to deliver previously unimaginable ...
Read more >
The experience economy, the ecosystem mandate, and why ...
As the experience economy and API economy collide, enterprise leaders must take a proactive approach and embrace a little-known but deeply ...
Read more >
A Web API ecosystem through feature-based reuse
We discuss a vision for developing Web API s based on reuse of interface parts called features. Through the introduction of 5 design...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found