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.

Lightweight eject

See original GitHub issue

I really like this project and the philosophy of not limiting the user by anything. Escape hatches via .babelrc and razzle.config.js are good, but I somehow miss full control over the config. I know that I could easily fork this project and adapt the code to my needs, but this is not my goal (probably I am totally wrong and forking is this way to go).

To explain my problem, take a look at the following use case. Let’s say I want to handle SVG files differently in webpack than other media files (for instance with svg-inline-loader).

As svg has been defined in https://github.com/jaredpalmer/razzle/blob/eb222411de3695789ec4495d3cbf2d41fc11e4be/packages/razzle/config/create-config.js#L88 (Note: This is an older version of create-config.js but it is still good to explain the problem), I had to do the following in razzle.config.js:


module.exports = {
  modify: (config, { target, dev }) => {
    // ...
    const loaders = [
      {
        test: /\.svg$/,
        use: [
          {
            loader: 'svg-inline-loader'
          }
        ]
      }
    ];

    // Exclude svg from default config
    // Dangerous as we are depending on the order of the predefined rules (!)
    config.module.rules[2].test = /\.(jpg|jpeg|png|gif|eot|ttf|woff|woff2)$/;

    config.module.rules = loaders.concat(config.module.rules);
    // ...
    return config;
  }
};

As already mentioned in the comment, this adaption is error prone, as it will break if any new rules are added or the order of them are changed. It would be cool to have something like an eject command in create-react-app, but probably only exposing the resulting webpack.config.js for prod and dev. Any thoughts?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
jchookcommented, Jan 6, 2019

You lose a lot of buy-in when you refuse to provide an easy opt-out.

3reactions
jaredpalmercommented, Jun 19, 2017

You are correct that this particular way of modifying razzle is very error prone and fragile. Instead of using the Array[i]. I suggest using Array.find or Array.findIndex. This is much more future proof as it will continue to work, even if a rule changes position.

As for razzle eject, it’s totally possible to build. To make life easier we would probably want to refactor create-config into 4 webpack.config.<target>.<env>.js files. Similarly to CRA, I’d want to setup a form asking why people are ejecting in the first place.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Buy Pitking Products Lightweight Aluminium 1/4 Turn Quick ...
These lightweight 1/4 turn self eject fasteners are made from aluminium and are 50% lighter than the Dzus steel equivalent. Swapping to these...
Read more >
Lightweight Easy to Install Durable SIM and Memory Card ...
Lightweight Easy to Install Durable SIM and Memory Card Tray Holder w/SIM Card Ejection Pin Compatible with Samsung Galaxy A6 SM-A600T1 Metro by...
Read more >
Mk17 Ejection Seat – Martin Baker
The Martin-Baker Mk17 ejection seat is ultra-lightweight, compact and very simple in both its design and operation, specifically developed for basic and primary ......
Read more >
EjectBar on the Mac App Store
A tiny, lightweight macOS menubar application to eject multiple mounted volumes in one click. Favorite a mounted volume to save it for quick...
Read more >
Claw Weeder gardening tool lightweight long shaft and easy eject ...
Lightweight long shaft and easy-eject design help to eliminate sore knees and back aches from bending, making cleanup quicker and easier Offset handle......
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