Skip to content

Commit

Permalink
build : compress build with terser
Browse files Browse the repository at this point in the history
  • Loading branch information
nuzulul committed Jun 24, 2024
1 parent 521db2c commit 1101908
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 18 deletions.
6 changes: 4 additions & 2 deletions config/rollup.config.build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';

export default [
{
Expand All @@ -9,7 +10,8 @@ export default [
file: 'dist/esm/webpeerjs.js',
format: 'es',
}
]
],
plugins: [nodeResolve({browser: true}), commonjs(),terser()]
},
{
input: 'src/umd.js',
Expand All @@ -20,6 +22,6 @@ export default [
name: 'webpeerjs',
}
],
plugins: [nodeResolve({browser: true}), commonjs()]
plugins: [nodeResolve({browser: true}), commonjs(),terser()]
}
]
65 changes: 51 additions & 14 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"removedir": "node -e \"var fs = require('fs'); try{process.argv.slice(1).map((fpath) => fs.rmdirSync(fpath, { recursive: true }))}catch(err){console.log(`Dist not found`)}; process.exit(0);\"",
"build-all": "tsc -p config/tsconfig-rollup.json && rollup -c temp/config/rollup.config.build.js && echo {\"type\": \"commonjs\"}>dist\\umd\\package.json && echo {\"type\": \"module\"}>dist\\esm\\package.json",
"build-types": "tsc -p config/tsconfig-esm.json",
"build": "npm run removedir dist temp && npm run build-all && npm run build-types",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "npm run removedir dist temp && npm run build-all",
"test": "cd test && cd project && npm start"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -70,6 +70,7 @@
"@eslint/js": "^9.4.0",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"eslint": "^9.4.0",
"globals": "^15.3.0",
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! WebpeerJS -- https://github.com/nuzulul/webpeerjs
const prefix = 'webpeerjs'
export const CONFIG_PREFIX = prefix
export const CONFIG_PROTOCOL = '/'+prefix+'/1.0.0'
Expand Down
1 change: 1 addition & 0 deletions src/webpeerjs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! WebpeerJS -- https://github.com/nuzulul/webpeerjs
import * as config from './config'
import {
mkErr,
Expand Down
48 changes: 48 additions & 0 deletions test/project/distesm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebpeerJS</title>
</head>
<body>
<h3>Basic Connection Demo of <a href="https://github.com/nuzulul/webpeerjs">WebpeerJS</a></h3>
<p><a href="index.html">link</a> | <a href="distesm.html">dist esm</a> | <a href="distumd.html">dist umd</a> </p>
<div id="app"><ul id="myList"></ul></div>

<script type="module">

import { webpeerjs } from './../../dist/esm/webpeerjs.js'

void async function main() {

function write(input){
const node = document.createElement("li")
const textnode = document.createTextNode(input)
node.appendChild(textnode)
document.getElementById("myList").appendChild(node)
}

const node = await webpeerjs.createWebpeer()

write(`My node id : ${node.id}`)

const room = 'myroom'

write(`joinRoom : ${room}`)

const [broadcast,listen,members] = node.joinRoom(room)

listen((message,id) => {
write(`Message from ${id} : ${message}`)
})

members((data) => {
write(`Members update : ${data}`)
broadcast('hello')
})

}()
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions test/project/distumd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebpeerJS</title>
</head>
<body>
<h3>Basic Connection Demo of <a href="https://github.com/nuzulul/webpeerjs">WebpeerJS</a></h3>
<p><a href="index.html">link</a> | <a href="distesm.html">dist esm</a> | <a href="distumd.html">dist umd</a> </p>
<div id="app"><ul id="myList"></ul></div>

<script src="./node_modules/webpeerjs/dist/umd/webpeerjs.js"></script>
<script>

void async function main() {

function write(input){
const node = document.createElement("li")
const textnode = document.createTextNode(input)
node.appendChild(textnode)
document.getElementById("myList").appendChild(node)
}

const node = await webpeerjs.createWebpeer()

write(`My node id : ${node.id}`)

const room = 'myroom'

write(`joinRoom : ${room}`)

const [broadcast,listen,members] = node.joinRoom(room)

listen((message,id) => {
write(`Message from ${id} : ${message}`)
})

members((data) => {
write(`Members update : ${data}`)
broadcast('hello')
})

}()
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/project/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</head>
<body>
<h3>Basic Connection Demo of <a href="https://github.com/nuzulul/webpeerjs">WebpeerJS</a></h3>
<p><a href="index.html">link</a> | <a href="distesm.html">dist esm</a> | <a href="distumd.html">dist umd</a> </p>
<div id="app"><ul id="myList"></ul></div>

<script type="module">
Expand Down

0 comments on commit 1101908

Please sign in to comment.