Skip to content

Commit

Permalink
Change build setup to allow building by any bundler, expose version
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Oct 26, 2020
1 parent 68387eb commit a9671f6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## next

- Changed build setup to allow building by any bundler that supports `browser` property in `package.json`
- Exposed version

## 0.3.0 (2020-09-28)

- Renamed `info()` method into `stringifyInfo()`
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Default: `false`

Stop collecting info for a value or not whenever circular reference is found. Setting option to `true` allows to find all circular references.

### version

The version of library, e.g. `"0.3.1"`.

## License

MIT
3 changes: 3 additions & 0 deletions browser-method-is-not-supported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = () => {
throw new Error('Method is not supported');
};
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"license": "MIT",
"repository": "discoveryjs/json-ext",
"main": "./src/index",
"browser": {
"./src/stringify-stream.js": "./browser-method-is-not-supported.js"
},
"scripts": {
"test": "mocha --reporter progress",
"lint": "eslint src test",
Expand All @@ -32,6 +35,7 @@
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"chalk": "^4.1.0",
"coveralls": "^3.1.0",
Expand Down
22 changes: 4 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
const path = require('path');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
const { terser } = require('rollup-plugin-terser');

function replaceContent(map) {
return {
name: 'file-content-replacement',
load(id) {
const key = path.relative('', id);
if (map.hasOwnProperty(key)) {
return map[key](id);
}
}
};
};

module.exports = {
input: 'src/index.js',
output: [
{ name: 'jsonExt', format: 'umd', file: 'dist/json-ext.js' },
{ name: 'jsonExt', format: 'umd', file: 'dist/json-ext.min.js', plugins: [terser()] }
{ name: 'jsonExt', format: 'umd', file: 'dist/json-ext.min.js', plugins: [terser({ compress: { passes: 2 } })] }
],
plugins: [
nodeResolve({ browser: true }),
replaceContent({
'src/stringify-stream.js': () => 'module.exports = "Method is not supported";'
}),
commonjs()
commonjs(),
json()
]
};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
version: require('../package.json').version,
stringifyInfo: require('./stringify-info'),
stringifyStream: require('./stringify-stream')
};

0 comments on commit a9671f6

Please sign in to comment.