Skip to content

Commit

Permalink
Remove ES module build
Browse files Browse the repository at this point in the history
As a workaround for all the Webpack users

Fixes #123
Fixes #87
Fixes #97
  • Loading branch information
TehShrike committed Oct 24, 2018
1 parent 0f5efc8 commit c63a55f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [3.0.0](https://github.com/KyleAMathews/deepmerge/releases/tag/v3.0.0)

- drop ES module build [#123](https://github.com/KyleAMathews/deepmerge/issues/123)

# [2.2.1](https://github.com/KyleAMathews/deepmerge/releases/tag/v2.2.1)

- bug: typescript export type was wrong [#121](https://github.com/KyleAMathews/deepmerge/pull/121)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"url": "git://github.com/KyleAMathews/deepmerge.git"
},
"main": "dist/umd.js",
"module": "dist/es.js",
"engines": {
"node": ">=0.10.0"
},
Expand Down
19 changes: 4 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@ Merges the enumerable attributes of two or more objects deeply.
> UMD bundle is 567B minified+gzipped

### Migration from 1.x to 2.0.0
### Migration from 1.x to 2+

[***Check out the changes from version 1.x to 2.0.0***](https://github.com/KyleAMathews/deepmerge/blob/master/changelog.md#200)

For the legacy array element-merging algorithm, see [the `arrayMerge` option below](#arraymerge).


### Webpack bug

If you have `require('deepmerge')` (as opposed to `import merge from 'deepmerge'`) anywhere in your codebase, Webpack 3 and 4 have a bug that [breaks bundling](https://github.com/webpack/webpack/issues/6584).

If you see `Error: merge is not a function`, add this alias to your Webpack config:

```
alias: {
deepmerge$: path.resolve(__dirname, 'node_modules/deepmerge/dist/umd.js'),
}
```


## Getting Started

### Example Usage
Expand Down Expand Up @@ -93,9 +80,11 @@ var merge = require('deepmerge')

ES Modules:
```
import merge from 'deepmerge'
import * from 'deepmerge'
```

(support for `import merge from 'deepmerge'` was removed because of a [Webpack bug](https://github.com/webpack/webpack/issues/6584)).


# API

Expand Down
9 changes: 4 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'

var pkg = require('./package.json')
const pkg = require(`./package.json`)

export default {
input: 'index.js',
name: 'deepmerge',
input: `index.js`,
name: `deepmerge`,
plugins: [
commonjs(),
resolve(),
],
output: [
{ file: pkg.main, format: 'umd' },
{ file: pkg.module, format: 'es' },
{ file: pkg.main, format: `umd` },
],
}

3 comments on commit c63a55f

@TrySound
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TehShrike The root of problems here is default export. I found it's quite useless (and as you can see painful) and do not use for a year. All similar problems are go away. Would you like to simply got rid from default and provide named exports instead? Like this

import { deepmerge, deepmergeAll } from 'deepmerge';
const { deepmerge, deepmergeAll } = require('deepmerge');

@TehShrike
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a breaking change, and I think it would make the module less ergonomic for CommonJS consumers.

I'm just going to leave things as they are until Webpack eventually fixes this bug maybe someday.

@TrySound
Copy link
Contributor

@TrySound TrySound commented on c63a55f Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there are two problems. 1. with webpack shitty interop, 2. with typescript which did not enabled esModuleInterop by default in recent major release.

I don't think webpack will ever fix it. Actually the best solution is disabling module field on user side. A lot of projects are broken if consumers uses commonjs. It's their problem and they should configure their project properly.

So there's no good reason to stuck with commonjs, nobody gonna fix it.

Please sign in to comment.