minimum example

This commit is contained in:
Daniel Bulant 2021-04-04 12:27:24 +02:00
commit c3a301a138
6 changed files with 70 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules
pnpm-lock.yaml

5
.nolluprc.js Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
contentBase: 'public',
port: 9001,
hot: true
};

15
package.json Normal file
View file

@ -0,0 +1,15 @@
{
"scripts": {
"clean": "shx rm -rf dist",
"start": "nollup -c --environment NODE_ENV:development",
"build": "npm run clean && rollup -c --environment NODE_ENV:production"
},
"devDependencies": {
"nollup": "^0.15.0",
"rollup": "^2.38.5",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-static-files": "0.0.1",
"rollup-plugin-terser": "^5.1.1",
"shx": "^0.3.2"
}
}

16
public/index.html Normal file
View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barebones</title>
</head>
<body>
<div id="app"></div>
<script>
const worker = new SharedWorker("/sharedworker.js");
worker.port.start();
worker.port.postMessage("test");
</script>
</body>
</html>

27
rollup.config.js Normal file
View file

@ -0,0 +1,27 @@
import node_resolve from 'rollup-plugin-node-resolve';
import static_files from 'rollup-plugin-static-files';
import { terser } from 'rollup-plugin-terser';
let config = {
input: './src/sharedworker.js',
output: {
dir: 'dist',
format: 'esm',
entryFileNames: '[name].js',
assetFileNames: '[name][extname]'
},
plugins: [
node_resolve()
]
}
if (process.env.NODE_ENV === 'production') {
config.plugins = config.plugins.concat([
static_files({
include: ['./public']
}),
terser()
]);
}
export default config;

5
src/sharedworker.js Normal file
View file

@ -0,0 +1,5 @@
self.port.start();
self.port.addEventListener("message", (...args) => {
console.log("message", ...args);
});