Skip to content

Commit

Permalink
Use babel (for Symbol polyfill). Also generate ES module
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 16, 2018
1 parent 74a97b6 commit c4f2c2d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 62 deletions.
81 changes: 81 additions & 0 deletions changelog.md
@@ -0,0 +1,81 @@
# Changelog

### 0.8.0

* The built is now being rolled up [#64](https://github.com/mweststrate/immer/pull/64) by [Arthur Denner](https://github.com/arthurdenner). A minified gzipped built is only 2kb!
* There are no longer separate builds available for the proxy and es5 implementation. The sources where merged to allow for more code reuse.
* The package now exposes an ES module as well.

### 0.7.0

* Immer will now use `Object.is` instead of `===` for equality checks

### 0.6.1

* Fixed issue where proxies inside new objects where not cleaned up. Fixes Fixes [#53](https://github.com/mweststrate/immer/issues/53)

### 0.6.0

* The default import now bundles both the es5 and proxy implementation as a convenient default. For more optimal bundle sizes, import `immer/proxy` or `immer/es5`

### 0.5.0

* Make sure es5.js is transpiled

### 0.4.2

* Fixed generating a wrong property descriptor for the `length` property of arrays. Fixes [#50](https://github.com/mweststrate/immer/issues/50)
* Defining custom properties on drafts is no longer supported

### 0.4.1

* Added UMD build

### 0.4.0

* Introduce support for [currying](https://github.com/mweststrate/immer#currying). [#37](https://github.com/mweststrate/immer/pull/37)
* Added argument checking
* The name of the immer import is now idiomatically `produce`. So the recommend import statement is: `import produce from "immer"`.

### 0.3.1

* Republished, somehow NPM still returned 0.2.2

### 0.3.0 (8-1-2018)

* Increased performance of the proxy-based implementation by a factor 2x - 3x. [#38](https://github.com/mweststrate/immer/pull/38)
* Improved typescript typings [#40](https://github.com/mweststrate/immer/pull/40) by [Julien Cavaleiro](https://github.com/Julienng)
* Added badges, coverage and typical project shizzle. [#25](https://github.com/mweststrate/immer/pull/25) by [Gregory Assasie](https://github.com/Gregjarvez) and [#39](https://github.com/mweststrate/immer/pull/39) by [Fadi Khadra](https://github.com/fkhadra)

### 0.2.2

* Fixed [#32](https://github.com/mweststrate/immer/issue/32): changes are not properly reflected in proxies when using for example `console.dir`

### 0.2.1

* Fixed: `immer/es5.js` was not packed into the package. PR [#28](https://github.com/mweststrate/immer/pull/28) by [Nicolas Lepage](https://github.com/nlepage)

### 0.2.0

* Immer now supports JavaScript engines without Proxies as well! Just require `immer` from `"immer/es5"`. See [#22](https://github.com/mweststrate/immer/pull/22)

### 0.1.2 (2-1-2018)

* Fixed issue where trailing commas could break consumers. Fixes [#21](https://github.com/mweststrate/immer/pull/21).

### 0.1.1 (2-1-2018)

* Fixed issue where TypeScript typings were not correctly exposed. Fixes [#18](https://github.com/mweststrate/immer/issue/18).

### 0.1.0 (1-1-2018)

* Fixed `immer` function export, it is now properly exposed as the `default` export. So `import immer from "immer"`. See [#15](https://github.com/mweststrate/immer/pull/15)
* Immer now automatically freezes any state modifications made. Turn this is using `setAutoFreeze(false)` for more efficiency in production builds. See [#15](https://github.com/mweststrate/immer/pull/15)
* Added support for frozen state trees in strict mode. See [#15](https://github.com/mweststrate/immer/pull/15)
* `immer` will now warn if you accidentally return something from the _thunk_. Fixes [#] through [#16](https://github.com/mweststrate/immer/pull/16/). By [Gregory Assasie](https://github.com/Gregjarvez).
* Proxies are now automatically cleaned up. This makes it impossible to read proxies after the `immer` function has finished. This prevents users from accidentally reading stale date. [#14](https://github.com/mweststrate/immer/pull/14) by [@benbraou](https://github.com/benbraou)

### 0.0.4 (31-12-2017)

* Added typescript typings [#11](https://github.com/mweststrate/immer/pull/11) by [@benbraou](https://github.com/benbraou)
* Fixed bug when setting properties to `undefined`. Fixes [#12](https://github.com/mweststrate/immer/issues/12) through [#13](https://github.com/mweststrate/immer/pull/13) by [@benbraou](https://github.com/benbraou)
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -3,6 +3,10 @@
"version": "0.7.0",
"description": "Create your next immutable state by mutating the current one",
"main": "dist/immer.js",
"umd:main": "dist/immer.umd.js",
"module": "dist/immer.module.js",
"jsnext:main": "dist/immer.module.js",
"react-native": "dist/immer.module.js",
"types": "./immer.d.ts",
"scripts": {
"test": "jest",
Expand Down Expand Up @@ -39,6 +43,7 @@
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-jest": "^22.0.4",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-modern-browsers": "^10.0.1",
Expand All @@ -53,7 +58,7 @@
"regenerator-runtime": "^0.11.1",
"rimraf": "^2.6.2",
"rollup": "^0.54.0",
"rollup-plugin-buble": "^0.18.0",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-filesize": "^1.5.0",
"rollup-plugin-node-resolve": "^3.0.2",
Expand Down
15 changes: 4 additions & 11 deletions readme.md
Expand Up @@ -10,7 +10,7 @@ _Create the next immutable state tree by simply modifying the current tree_
---

* NPM / Yarn: `npm install immer`
* CDN: https://unpkg.com/immer/dist/immer.umd.js or https://unpkg.com/immer/dist/es5.umd.js. Exposed global is `immer`.
* CDN: https://unpkg.com/immer/dist/immer.umd.js. Exposed global is `immer`.

---

Expand Down Expand Up @@ -86,6 +86,7 @@ expect(nextState[1]).not.toBe(baseState[1])
* Object freezing out of the box
* Deep updates are a breeze
* Boilerplate reduction. Less noise, more concise code.
* Small: bundled and minified: 2KB.

Read further to see all these benefits explained.

Expand Down Expand Up @@ -182,20 +183,12 @@ One think to keep in mind; you cannot use this construction to initialize an uni
It is by default enabled.
Use `setAutoFreeze(true / false)` to turn this feature on or off.

## Using Immer on older JavaScript environments
## Immer on older JavaScript environments?

By default `produce` tries to use proxies for optimal performance.
However, on older JavaScript engines `Proxy` is not available.
For example, Microsoft Internet Explorer or React Native on Android.
For example, when running Microsoft Internet Explorer or React Native on Android.
In such cases Immer will fallback to an ES5 compatible implementation which works identical, but is a bit slower.
However, if you want to slim down your bundle, you could only include the Proxy based implementation by importing from `immer/proxy`.

An overview of the available builds:

Immer exposes its functionality in 3 different ways:
* `import produce from "immer"`, the default, ships with both the Proxy and ES5 compatible implementation, and picks at runtime the best matching one. This is the most convenient, but adds the most to the bundle size (~2KB)
* `import produce from "immer/proxy"`: This build is optimized for modern browser, which support Proxies and other modern language features, and doesn't polyfill things like `Symbol`. Use this if you are targetting a modern environment only
* `import produce from "immer/es5"`: Only bundle the ES5 compatible implementation (which of course also works for modern browsers)

## Pitfalls

Expand Down
42 changes: 29 additions & 13 deletions rollup.config.js
@@ -1,16 +1,16 @@
import {minify} from "uglify-es"
import buble from "rollup-plugin-buble"
import commonjs from "rollup-plugin-commonjs"
import filesize from "rollup-plugin-filesize"
import resolve from "rollup-plugin-node-resolve"
import uglify from "rollup-plugin-uglify"
import babel from "rollup-plugin-babel"

function getConfig(format) {
function getConfig(dest, format, ugly) {
const conf = {
input: "src/index.js",
output: {
exports: "named",
file: `dist/immer${format === "umd" ? ".umd" : ""}.js`,
file: dest,
format,
name: "immer",
sourcemap: true
Expand All @@ -20,21 +20,37 @@ function getConfig(format) {
jsnext: true
}),
commonjs(),
buble(),
uglify(
{
warnings: true,
toplevel: true
},
minify
),
babel({
babelrc: false,
presets: [
[
"env",
{
modules: false
}
]
],
plugins: ["external-helpers"]
}),
ugly &&
uglify(
{
warnings: true,
toplevel: true
},
minify
),
filesize()
]
].filter(Boolean)
}

return conf
}

const config = [getConfig("cjs"), getConfig("umd")]
const config = [
getConfig("dist/immer.js", "cjs", false),
getConfig("dist/immer.umd.js", "umd", true),
getConfig("dist/immer.module.js", "es", false)
]

export default config
61 changes: 24 additions & 37 deletions yarn.lock
Expand Up @@ -32,22 +32,6 @@ acorn-globals@^4.0.0:
dependencies:
acorn "^5.0.0"

acorn-jsx@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
dependencies:
acorn "^3.0.4"

acorn5-object-spread@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/acorn5-object-spread/-/acorn5-object-spread-4.0.0.tgz#d5758081eed97121ab0be47e31caaef2aa399697"
dependencies:
acorn "^5.1.2"

acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^5.0.0, acorn@^5.1.2, acorn@^5.2.1:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"
Expand Down Expand Up @@ -392,6 +376,12 @@ babel-plugin-check-es2015-constants@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-external-helpers@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-external-helpers/-/babel-plugin-external-helpers-6.22.0.tgz#2285f48b02bd5dede85175caf8c62e86adccefa1"
dependencies:
babel-runtime "^6.22.0"

babel-plugin-istanbul@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.5.tgz#6760cdd977f411d3e175bb064f2bc327d99b2b6e"
Expand Down Expand Up @@ -863,19 +853,6 @@ bser@^2.0.0:
dependencies:
node-int64 "^0.4.0"

buble@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/buble/-/buble-0.18.0.tgz#63b338b8248c474b46fd3e3546560ae08d8abe91"
dependencies:
acorn "^5.1.2"
acorn-jsx "^3.0.1"
acorn5-object-spread "^4.0.0"
chalk "^2.1.0"
magic-string "^0.22.4"
minimist "^1.2.0"
os-homedir "^1.0.1"
vlq "^0.2.2"

builtin-modules@^1.0.0, builtin-modules@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
Expand Down Expand Up @@ -917,7 +894,7 @@ chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0:
chalk@^2.0.0, chalk@^2.0.1:
version "2.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba"
dependencies:
Expand Down Expand Up @@ -1233,6 +1210,10 @@ estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

estree-walker@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.2.1.tgz#bdafe8095383d8414d5dc2ecf4c9173b6db9412e"

estree-walker@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.3.1.tgz#e6b1a51cf7292524e7237c312e5fe6660c1ce1aa"
Expand Down Expand Up @@ -2504,7 +2485,7 @@ optionator@^0.8.1:
type-check "~0.3.2"
wordwrap "~1.0.0"

os-homedir@^1.0.0, os-homedir@^1.0.1:
os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"

Expand Down Expand Up @@ -2903,12 +2884,11 @@ rimraf@2, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2:
dependencies:
glob "^7.0.5"

rollup-plugin-buble@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-buble/-/rollup-plugin-buble-0.18.0.tgz#6e20d1b2840c59eb496b9f954f75243e51786ac1"
rollup-plugin-babel@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-3.0.3.tgz#63adedc863130327512a4a9006efc2241c5b7c15"
dependencies:
buble "^0.18.0"
rollup-pluginutils "^2.0.1"
rollup-pluginutils "^1.5.0"

rollup-plugin-commonjs@^8.2.6:
version "8.2.6"
Expand Down Expand Up @@ -2944,6 +2924,13 @@ rollup-plugin-uglify@^2.0.1:
dependencies:
uglify-js "^3.0.9"

rollup-pluginutils@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
dependencies:
estree-walker "^0.2.1"
minimatch "^3.0.2"

rollup-pluginutils@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz#7ec95b3573f6543a46a6461bd9a7c544525d0fc0"
Expand Down Expand Up @@ -3338,7 +3325,7 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"

vlq@^0.2.1, vlq@^0.2.2:
vlq@^0.2.1:
version "0.2.3"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26"

Expand Down

0 comments on commit c4f2c2d

Please sign in to comment.