From cf540f4a763867ceb117bf9eb8faf6763a650023 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Thu, 24 Feb 2022 18:09:01 -0500 Subject: [PATCH] Publish both esm and cjs --- package.json | 18 +++++++++++++++--- rollup.config.js | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 rollup.config.js diff --git a/package.json b/package.json index fe373baa..8c7ddfc9 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,25 @@ "name": "@testing-library/jest-dom", "version": "0.0.0-semantically-released", "description": "Custom jest matchers to test the state of the DOM", - "main": "dist/index.js", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "exports": { + ".": { + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js" + }, + "./matchers": { + "require": "./dist/cjs/matchers.js", + "import": "./dist/esm/matchers.js" + } + }, "engines": { "node": ">=8", "npm": ">=6", "yarn": ">=1" }, "scripts": { - "build": "kcd-scripts build", + "build": "rollup -c", "format": "kcd-scripts format", "lint": "kcd-scripts lint", "setup": "npm install && npm run validate -s", @@ -46,7 +57,8 @@ "jest-watch-select-projects": "^2.0.0", "jsdom": "^16.2.1", "kcd-scripts": "^11.1.0", - "pretty-format": "^25.1.0" + "pretty-format": "^25.1.0", + "rollup": "^2.68.0" }, "eslintConfig": { "extends": "./node_modules/kcd-scripts/eslint.js", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..81b5e042 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,23 @@ +import path from 'path' +import pkg from './package.json' + +export default [ + { + input: { + index: 'src/index.js', + matchers: 'src/matchers.js', + }, + output: [ + { + dir: path.dirname(pkg.exports['./matchers'].import), + format: 'esm', + }, + { + dir: path.dirname(pkg.exports['./matchers'].require), + format: 'cjs', + }, + ], + external: id => + !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), + }, +]