Skip to content

Commit

Permalink
chore: updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishant Mendiratta authored and Nishant Mendiratta committed Sep 23, 2023
1 parent 0cc73bf commit 650d676
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ Output file is generated in the current directory. It will contain minified file
> uglifymyjs —version
```

# Usage Example
See [Sample](./Sample).

# Dependency
The tool is built on top of `uglifyjs-webpack-plugin`. Following is the fixed configuration currently it is using. Feel free add new issues if you want any customization.
```
{
cache: false,
parallel: true,
uglifyOptions: {
compress: {
drop_console: true,
warnings: false,
},
toplevel: true,
keep_classnames: undefined,
keep_fnames: false,
nameCache: null,
output: {
beautify: false,
comments: false,
},
compress: true,
ecma: 6,
mangle: true,
},
sourceMap: true,
}
```

# Contributing

This library is designed to support JS files - i you want to add a new language support, we'd love you to contribute them here.
Expand All @@ -33,6 +63,8 @@ Please see [Coding Guidelines](https://github.com/nishantmendiratta/uglify-my-js

File issues in the **Issues** tab in GitHub



# Changelog

See [CHANGELOG](./CHANGELOG.md).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uglify-my-js",
"version": "1.1.12",
"version": "1.1.13",
"description": "Simple cli tool to minify javascript a file",
"main": "bin/index.js",
"bin": {
Expand Down
1 change: 0 additions & 1 deletion sample.js

This file was deleted.

32 changes: 32 additions & 0 deletions sample/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
(function (window, document, tag, url, name, a, m) {
window[name] = window[name] || function () {
(window[name].q = window[name].q || []).push(arguments)
}, window[name].l = 1 * new Date();
a = document.createElement(tag),
m = document.getElementsByTagName(tag)[0];
a.async = 1;
a.src = url;
m.parentNode.insertBefore(a, m);
})(window, document, 'script', 'main.bundle.min.js', 'myThirdPartyLib');

function executeMinifiedLib() {
const element = document.getElementById('myThirdPartyLib-root');
window.myThirdPartyLib.appendNewElementToRoot(element);
}
window.onload = function(e) {
executeMinifiedLib();
}
</script>
<title>Sample HTML</title>
</head>
<body>
<div id="myThirdPartyLib-root"></div>

</body>
</html>
2 changes: 2 additions & 0 deletions sample/main.bundle.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 sample/main.bundle.min.js.map

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

15 changes: 15 additions & 0 deletions sample/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function (window) {
appendNewElementToRoot = function (element) {
if (!element) {
return;
}

const h1 = document.createElement('h1');
const textNode = document.createTextNode('Hello From H1');
h1.appendChild(textNode);
element.appendChild(h1);
};

window.myThirdPartyLib = {appendNewElementToRoot};
})(window);

0 comments on commit 650d676

Please sign in to comment.