Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 5897932

Browse files
committed
feat(bundle): bundling the module similar to js-bson
BREAKING CHANGE: The default exported name for the module is now EJSON, mirroring the js-bson module's exported BSON name.
1 parent c4fc462 commit 5897932

File tree

3 files changed

+123
-39
lines changed

3 files changed

+123
-39
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22
"name": "mongodb-extjson",
33
"version": "4.0.0-rc1",
44
"description": "MongoDB Extended JSON library",
5-
"main": "index.js",
6-
"browser": "dist/mongodb-extjson.js",
7-
"scripts": {
8-
"test": "npm run-script test-node && npm run-script test-browser",
9-
"test-node": "mocha test/",
10-
"test-browser": "karma start",
11-
"docs": "jsdoc2md --heading-depth 3 --template etc/README.hbs --plugin dmd-clear --files lib/ext_json.js > README.md",
12-
"coverage": "istanbul cover _mocha -- --recursive -t --ui tdd test/",
13-
"lint": "eslint lib test",
14-
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
15-
"build": "rollup -c",
16-
"prepublishOnly": "npm run build",
17-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
18-
},
195
"repository": {
206
"type": "git",
217
"url": "git+https://github.com/mongodb-js/mongodb-extjson.git"
@@ -35,9 +21,28 @@
3521
"url": "https://github.com/mongodb-js/mongodb-extjson/issues"
3622
},
3723
"homepage": "https://github.com/mongodb-js/mongodb-extjson#readme",
24+
"main": "lib/ext_json.js",
25+
"module": "dist/mongodb-extjson.esm.js",
26+
"browser": {
27+
"./index.js": "./dist/mongodb-extjson.browser.umd.js",
28+
"./dist/mongodb-extjson.esm.js": "./dist/mongodb-extjson.browser.esm.js"
29+
},
30+
"scripts": {
31+
"test": "npm run-script test-node && npm run-script test-browser",
32+
"test-node": "mocha test/",
33+
"test-browser": "karma start",
34+
"docs": "jsdoc2md --heading-depth 3 --template etc/README.hbs --plugin dmd-clear --files lib/ext_json.js > README.md",
35+
"coverage": "istanbul cover _mocha -- --recursive -t --ui tdd test/",
36+
"lint": "eslint lib test",
37+
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
38+
"build": "rollup -c",
39+
"prepublishOnly": "npm run build",
40+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
41+
},
3842
"devDependencies": {
3943
"babel-core": "^6.26.0",
4044
"babel-preset-env": "^1.6.1",
45+
"babel-plugin-external-helpers": "^6.22.0",
4146
"chai": "^4.1.2",
4247
"conventional-changelog-cli": "^1.3.5",
4348
"dmd-clear": "^0.1.2",

rollup.config.js

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,97 @@
1-
import commonjs from 'rollup-plugin-commonjs';
2-
import nodeResolve from 'rollup-plugin-node-resolve';
3-
import babel from 'rollup-plugin-babel';
1+
'use strict';
42

5-
export default {
6-
input: 'index.js',
7-
output: {
8-
file: 'dist/mongodb-extjson.js',
9-
format: 'umd',
10-
name: 'mongodb-extjson',
11-
},
12-
plugins: [
13-
nodeResolve(),
14-
commonjs(),
15-
babel({
16-
presets: [
17-
[
18-
'env',
19-
{
20-
modules: false
21-
}
22-
]
3+
const pkg = require('./package.json');
4+
const commonjs = require('rollup-plugin-commonjs');
5+
const nodeBuiltins = require('rollup-plugin-node-builtins');
6+
const nodeResolve = require('rollup-plugin-node-resolve');
7+
const babel = require('rollup-plugin-babel');
8+
9+
const input = 'lib/ext_json.js';
10+
const plugins = [
11+
nodeResolve(),
12+
commonjs(),
13+
nodeBuiltins(),
14+
babel({
15+
plugins: ['external-helpers'],
16+
presets: [
17+
[
18+
'env',
19+
{
20+
modules: false
21+
}
2322
]
24-
})
25-
],
26-
external: ['bson'],
27-
}
23+
]
24+
})
25+
];
26+
27+
const browserPlugins = [
28+
nodeResolve({
29+
browser: true,
30+
preferBuiltins: false
31+
}),
32+
commonjs(),
33+
nodeBuiltins(),
34+
babel({
35+
plugins: ['external-helpers'],
36+
presets: [
37+
[
38+
'env',
39+
{
40+
modules: false
41+
}
42+
]
43+
]
44+
})
45+
];
46+
47+
const external = Object.keys(pkg.dependencies || {});
48+
const defaultName = 'EJSON';
49+
50+
module.exports = [
51+
{
52+
input,
53+
output: {
54+
file: 'dist/mongodb-extjson.esm.js',
55+
format: 'es',
56+
name: defaultName,
57+
exports: 'named'
58+
},
59+
plugins,
60+
external
61+
},
62+
{
63+
input,
64+
output: {
65+
file: 'dist/mongodb-extjson.browser.umd.js',
66+
format: 'umd',
67+
name: defaultName,
68+
exports: 'named',
69+
globals: {
70+
buffer: 'Buffer'
71+
}
72+
},
73+
plugins: browserPlugins,
74+
external
75+
},
76+
{
77+
input,
78+
output: {
79+
file: 'dist/mongodb-extjson.browser.esm.js',
80+
format: 'es',
81+
name: defaultName,
82+
exports: 'named'
83+
},
84+
plugins: browserPlugins,
85+
external
86+
},
87+
{
88+
input,
89+
output: {
90+
file: 'dist/mongodb-extjson.bundle.js',
91+
format: 'iife',
92+
name: defaultName,
93+
exports: 'named'
94+
},
95+
plugins: browserPlugins
96+
}
97+
];

0 commit comments

Comments
 (0)