Code Monkey home page Code Monkey logo

Comments (2)

developit avatar developit commented on June 12, 2024

Hi @mikestead - would something like this work?

if (typeof process!=='undefined' && process.env.NODE_ENV!=='production') {

} else {

}

FWIW, I have found that you have to add a tiny bit extra in DefinePlugin to get things removed:

new DefinePlugin({
  process: {},
  'process.env': {},
  'process.env.NODE_ENV': JSON.stringify('production')
})

from proptypes.

mikestead avatar mikestead commented on June 12, 2024

Thanks for the input and tip, if I add process and process.env to the define plugin with no changes to PropTypes lib I do indeed see a little more code removed, and from react-router as well as preact/preact-compat.

libs.e47828f.js   129 kB    1, 2  [emitted]  libs 

I guess that's for code that also checks the parent chain of process.env.NODE_ENV in a conditional.

You are also correct the following does seem to work, and without touching the DefinePlugin.

if (typeof process!=='undefined' && process.env.NODE_ENV!=='production') {

But we're obv not checking for env here. If I add that check code isn't stripped... unless I go make those additions to the DefinePlugin :)

For backwards compatibility I tried switching it to

if (typeof process!=='undefined' && process.env.NODE_ENV==='production') {

and inverting the if else blocks, but then the code wasn't stripped. I guess Uglify may only like stripping from the if block?

If I swap back and then add process and process.env to DefinePlugin I can use an OR

if (typeof process==='undefined' || !process.env || process.env.NODE_ENV!=='production') { // dev

Let me know what you want to do, if anything and I'm happy to open a pull request.

from proptypes.

Related Issues (9)

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.