Skip to content

Commit

Permalink
Added .embed version
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Sierociński committed Sep 10, 2020
1 parent f8bc31c commit 13e2dbb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ console.log(BrowserInfo.version); // print detected browser's version string
console.log(BrowserInfo.os); // print detected OS name
```

### Auto Detect and Embed

In `dist` directory there is a file with `.embed` sufix. Importing this library into your UI will cause calling
`detect()` method and assigning `BrowserInfo` to `window.navigator.browserInfo` - this way it is accessible globally.

```js
import '@smartbear/browser-info/dist/smartbear-browser-info.embed.min'

console.log(window.navigator.browserInfo);
```

## License

This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
3 changes: 3 additions & 0 deletions dist/smartbear-browser-info.embed.min.js

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

1 change: 1 addition & 0 deletions dist/smartbear-browser-info.embed.min.js.map

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

2 changes: 1 addition & 1 deletion dist/smartbear-browser-info.js

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

2 changes: 1 addition & 1 deletion dist/smartbear-browser-info.min.js

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

2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smartbear/browser-info",
"version": "1.0.1",
"version": "1.1.0",
"description": "Tiny developer-friendly JS library that provides information about host browser",
"main": "dist/smartbear-browser-info.min.js",
"scripts": {
Expand Down
41 changes: 34 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ for(const ext of external) {
}

const safeName = $package.name.replace(/@/g, '').replace(/\//g, '-');
const output = function(min) {

function getOutput(min, sufix = '') {
return {
file: 'dist/' + safeName + (min ? '.min' : '') + '.js',
file: `dist/${safeName}${sufix}${(min ? '.min' : '')}.js`,
format: 'umd',
name: $package.name,
banner: `/* ${$package.name} v${$package.version} ` +
Expand All @@ -27,9 +28,9 @@ const output = function(min) {
globals,
sourcemap: true
};
};
}

const getBabelPlugin = function() {
function getBabelPlugin() {
return babel({
exclude: 'node_modules/**',
presets: [
Expand All @@ -43,13 +44,28 @@ const getBabelPlugin = function() {
]
]
});
};
}

function getTerserPlugin() {
return terser({
output: {
comments: (node, comment) => {
if (comment.type === "comment2") {
// multiline comment
return /LICENSE|\(c\)/.test(comment.value);
}
return false;
}
}
});
}


export default [
// Uncompressed config
{
input,
output: output(),
output: getOutput(),
plugins: [
del({
targets: 'dist/*',
Expand All @@ -63,7 +79,7 @@ export default [
// Compressed config
{
input,
output: output(true),
output: getOutput(true),
plugins: [
getBabelPlugin(),
terser({
Expand All @@ -79,5 +95,16 @@ export default [
})
],
external
},

// Embed version
{
input: 'src/embed.js',
output: getOutput(true, '.embed'),
plugins: [
getBabelPlugin(),
getTerserPlugin()
],
external
}
];
4 changes: 4 additions & 0 deletions src/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import BrowserInfo from './index';
window.navigator.browserInfo = BrowserInfo;
BrowserInfo.detect();
export default BrowserInfo;

0 comments on commit 13e2dbb

Please sign in to comment.