Giter Club home page Giter Club logo

Comments (1)

mahieyin-rahmun avatar mahieyin-rahmun commented on June 9, 2024 1

Okay. This was a ride.

TL;DR: Install "@babel/plugin-proposal-object-rest-spread" if you are going to use the spread operator, e.g. { ... state, rest }

Details:

After studying webpack and babel in general, I had a few ideas. One of them was to disable production mode in the build script.

cross-env NODE_ENV=production webpack --mode production --config webpack.build.config.js

became

cross-env NODE_ENV=production webpack --config webpack.build.config.js

This basically stopped the bundled js files from being minified/uglified, so I could take a look at it.

Note: This usually spits out errors from webpack that no mode was set in the config files, so I added mode: "none" in the config files as well.

Then taking a look at the bundled js, I saw the error was in the following line from my reducer:

// counterReducer.js
return 
{
--> ...state,
    count: state.count + 1
}

The problem was babel being unable to understand what the heck this was. So, I looked this issue up, and came across @babel/plugin-proposal-object-rest-spread. I installed the plugin using npm i --save @babel/plugin-proposal-object-rest-spread and included it in .babelrc file.

// .babelrc file
{
  ...
  "plugins": ["@babel/plugin-proposal-object-rest-spread"]
}

And it began to work perfectly fine in both development and production mode.

Perhaps all of the above could be avoided if I had simply used the core JS API, e.g.

Object.assign({}, state, { count: state.count + 1 })

but I haven't tested it.

from electron-react-webpack-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.