Comments (10)
Not sure I follow the question - we just use process.env.NODE_ENV
in the source to hook into envify when generating the production and development builds.
I can totally see explaining how that works in the source, because I can see how that would be unclear. Is that what you are referring to?
from seamless-immutable.
Hello, my question is: In Node, what are the ways to switch on the dev or the prod mode?
I have seen the NODE_ENV in the code without really understand when it is effective so likely the line 3 isn't true.
from seamless-immutable.
I still don't quite follow. This is how you do it for Node in general, but in the specific case of seamless-immutable, it's only used by envify when building the development and production builds.
You won't see NODE_ENV
in the outputted development build or production build, because envify
strips it out. Does that clarify?
from seamless-immutable.
I believe what @jakubholynet means is how do you switch between using the dev build and and production build. The package.json file for seamless-immutable points to the development build, which in my opinion is not ideal. Really it should point to the actual source. If users want to perform optimisations based on environment (i.e. using envify or webpack's define plugin), they should be able to do it themselves in their build step. This is how React does it and it works well; it gives the developer the power to choose.
To answer @jakubholynet 's question, if you are using webpack you can alias seamless-immutable to get different builds. Personally I have my webpack config set up like so:
module.exports = {
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": '"' + (process.env.NODE_ENV || "development") + '"'
})
],
resolve: {
alias: {
"seamless-immutable$": path.resolve(__dirname, "node_modules/seamless-immutable/src/seamless-immutable.js")
}
}
};
from seamless-immutable.
Thanks for clarifying! A few thoughts:
- The current source can't be used in development or production on a normal web page, as until
envify
has been done, references toprocess.env
will still be around waiting to break. So I don't think that's the right default at the moment. - Not everyone needs the performance optimizations provided by "prod mode," but this is a library built around strong guarantees of immutability, so I think the default should be that those strong guarantees are enforced. They are enforced in the development build, but not in the production build, so I think the development build is the better default.
- I haven't looked at that part of React's source, but I'm guessing they code defensively around
process.env
so that things won't break ifenvify
hasn't been run. I'm open to that approach so long as the post-envify
, post-uglify
production build doesn't end up with any lingering unnecessary checks as a result. This isn't a priority for me, but a PR would certainly be welcome!
from seamless-immutable.
Yeah so what they do in React is something like this:
var __DEV__ = process && process.env && process.env.NODE_ENV === "development";
var __PROD__ = process && process.env && process.env.NODE_ENV === "production";
if (__DEV__) {
//do dev-only stuff
}
The envify-uglify combo will cause all those conditional statements to be removed in production, so no lingering checks.
I'll see if i can get a PR in some time!
from seamless-immutable.
Sounds good! 👍
from seamless-immutable.
Sorry for a late response. Thanks, @oliverwoodings, for the clarifying on my behalf and for the response. I was interested both in being able to switch between dev/prod manually (depending on what I require
) and in a build step. I have the answers I need but perhaps they should be included in the docs [more visibly] as well? Thank you all!
from seamless-immutable.
Thanks for the Webpack example. How can I specify which build to use using Browserify?
from seamless-immutable.
If your webpack configuration uses the default mainFields
, or use defaults values, with browser
first before main
, the development build from seamless-immutable will be used, even though you set NODE_ENV
to prod.
See https://webpack.js.org/configuration/resolve/#resolve-mainfields
The default target of webpack is web
, so therefore, every use will use the development version by default.
from seamless-immutable.
Related Issues (20)
- Make `without` support removing item from an array HOT 4
- how to use splice like array HOT 1
- Internet Explorer tests are failing HOT 4
- Issue regarding null values HOT 5
- Why are IE tests failing? HOT 3
- How to apply splice with seamless-immutable? HOT 1
- Merge does not work with class instances
- __immutable_invariants_hold is enumerable on Edge HOT 1
- Garbage collector features? HOT 1
- Performance characteristics
- Any difference with deepCopy? HOT 1
- [types] Mixin not applied to nested objects HOT 1
- flatMap not working HOT 2
- Add documentation for merge mode
- Files not being replaced on a deep merge
- Fails on IE 11 HOT 1
- TypeError: Object(...) is not a function HOT 1
- Lodash Vulnerability Problem
- Is the project still maintained? HOT 2
- immutable object causes rapid memory growth HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seamless-immutable.