Skip to content

Commit

Permalink
feat: add esm bundle
Browse files Browse the repository at this point in the history
bundle using rollup
  • Loading branch information
unional committed Nov 24, 2022
1 parent b0fec27 commit 5ea3867
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
coverage/
dist/
umd/
.tern-port
20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
28 changes: 28 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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()]
}];
9 changes: 9 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
@@ -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();
})

0 comments on commit 5ea3867

Please sign in to comment.