diff --git a/.eslintignore b/.eslintignore index 378eac2..76668dd 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,3 @@ build +es +cjs diff --git a/.gitignore b/.gitignore index dfd8ee9..5c8c999 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build +es +cjs node_modules npm-debug.log .idea/ diff --git a/README.md b/README.md index c4e0c86..77ba925 100644 --- a/README.md +++ b/README.md @@ -38,16 +38,17 @@ yarn add react-waypoint ## Usage ```jsx -var Waypoint = require('react-waypoint'); -``` +import Waypoint from 'react-waypoint'; -```jsx ``` +*Alternatively, you can also use the ES module that this package provides: +`import Waypoint from 'react-waypoint/es'`.* + A waypoint normally fires `onEnter` and `onLeave` as you are scrolling, but it can fire because of other events too: diff --git a/package.json b/package.json index 6cb26d5..743dc1e 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,7 @@ "name": "react-waypoint", "version": "7.3.0", "description": "A React component to execute a function whenever you scroll to an element.", - "main": "build/index.js", - "module": "build/index.mjs", + "main": "cjs/index.js", "types": "index.d.ts", "repository": { "type": "git", @@ -15,7 +14,7 @@ "build": "npm run clean && rollup -c", "check-changelog": "expr $(git status --porcelain 2>/dev/null| grep \"^\\s*M.*CHANGELOG.md\" | wc -l) >/dev/null || (echo 'Please edit CHANGELOG.md' && exit 1)", "check-only-changelog-changed": "(expr $(git status --porcelain 2>/dev/null| grep -v \"CHANGELOG.md\" | wc -l) >/dev/null && echo 'Only CHANGELOG.md may have uncommitted changes' && exit 1) || exit 0", - "clean": "rimraf build", + "clean": "rimraf es cjs", "lint": "eslint . --ext .js,.jsx", "postversion": "git commit package.json CHANGELOG.md -m \"Version $npm_package_version\" && npm run tag && git push && git push --tags && npm publish", "prepublish": "in-publish && safe-publish-latest && npm run build || not-in-publish", diff --git a/rollup.config.js b/rollup.config.js index 0c45ff2..247c84c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -10,7 +10,7 @@ export default [ ], output: [ { file: pkg.main, format: 'cjs' }, - { file: pkg.module, format: 'es' } + { file: 'es/index.mjs', format: 'es' } ], plugins: [ babel({