From 5ea3867e42a82c5a4f3c78db2033da5801232715 Mon Sep 17 00:00:00 2001 From: unional Date: Wed, 23 Nov 2022 13:15:23 -0800 Subject: [PATCH] feat: add esm bundle bundle using rollup --- .github/workflows/ci.yml | 1 + .gitignore | 1 + package.json | 20 ++++++++------------ rollup.config.mjs | 28 ++++++++++++++++++++++++++++ test/test.mjs | 9 +++++++++ 5 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 rollup.config.mjs create mode 100644 test/test.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7a9975..978f940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: node-version: ${{ matrix.node }} - run: npm install - run: npm test + - run: npm test-esm - uses: coverallsapp/github-action@1.1.3 if: matrix.node == 18 with: diff --git a/.gitignore b/.gitignore index 66275fe..aa9af5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ coverage/ +dist/ umd/ .tern-port diff --git a/package.json b/package.json index 9ab8151..0b88c12 100644 --- a/package.json +++ b/package.json @@ -8,28 +8,23 @@ "require": "./index.js", "types": "./index.d.ts" }, - "./umd/eventemitter3.js": { - "import": "./umd/eventemitter3.js", - "require": "./umd/eventemitter3.js", - "types": "./index.d.ts" - }, "./package.json": "./package.json" }, "main": "index.js", "types": "index.d.ts", "scripts": { - "browserify": "rimraf -rf umd && mkdir umd && browserify index.js -s EventEmitter3 -o umd/eventemitter3.js", - "minify": "uglifyjs umd/eventemitter3.js --source-map -cm -o umd/eventemitter3.min.js", + "rollup": "rimraf dist umd && rollup -c", "benchmark": "find benchmarks/run -name '*.js' -exec benchmarks/start.sh {} \\;", "test": "c8 --reporter=lcov --reporter=text mocha test/test.js", - "prepublishOnly": "npm run browserify && npm run minify", + "test-esm": "c8 --reporter=lcov --reporter=text mocha test/test.mjs", + "prepublishOnly": "npm run rollup", "test-browser": "node test/browser.js" }, "files": [ "index.js", "index.mjs", "index.d.ts", - "umd" + "dist" ], "repository": { "type": "git", @@ -58,14 +53,15 @@ "url": "https://github.com/primus/eventemitter3/issues" }, "devDependencies": { + "@rollup/plugin-commonjs": "^23.0.2", + "@rollup/plugin-terser": "^0.1.0", "assume": "^2.2.0", - "browserify": "^17.0.0", "c8": "^7.3.1", "mocha": "^10.0.0", "pre-commit": "^1.2.0", "rimraf": "^3.0.2", + "rollup": "^3.4.0", "sauce-browsers": "^3.0.0", - "sauce-test": "^1.3.3", - "uglify-js": "^3.9.0" + "sauce-test": "^1.3.3" } } diff --git a/rollup.config.mjs b/rollup.config.mjs new file mode 100644 index 0000000..e95d5e0 --- /dev/null +++ b/rollup.config.mjs @@ -0,0 +1,28 @@ +import commonjs from '@rollup/plugin-commonjs'; +import terser from '@rollup/plugin-terser'; + +export default [{ + input: './index.mjs', + output: { + file: 'dist/eventemitter3.esm.js', + format: 'es' + }, + plugins: [commonjs()] +}, { + input: './index.js', + output: { + format: 'umd', + name: 'EventEmitter3', + file: 'dist/eventemitter3.umd.js' + }, + plugins: [commonjs()] +}, { + input: './index.js', + output: { + compact: true, + format: 'umd', + name: 'EventEmitter3', + file: 'dist/eventemitter3.umd.min.js' + }, + plugins: [commonjs(), terser()] +}]; diff --git a/test/test.mjs b/test/test.mjs new file mode 100644 index 0000000..7b50c82 --- /dev/null +++ b/test/test.mjs @@ -0,0 +1,9 @@ +import EventEmitterDefault, { EventEmitter } from '../index.mjs'; + +it('exports `EventEmitter` as default export', () => { + new EventEmitterDefault(); +}) + +it('exports `EventEmitter` as a named export', () => { + new EventEmitter(); +})