diff --git a/.gitignore b/.gitignore index 2274cf0..26a971c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ yarn.lock node_modules *.wasm -out.js -dist +public/main.js diff --git a/Dockerfile b/Dockerfile index 15688be..488b66f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,13 @@ FROM node:14-alpine as build WORKDIR /app -COPY index.html main.js package.json webpack.config.js /app/ +COPY index.html main.js package.json build.js /app/ RUN yarn \ - && npm run build + && yarn run build FROM nginx:stable-alpine as nginx-nostr-relay-registry COPY ./nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf -COPY --from=build /app/dist /app \ No newline at end of file +COPY --from=build /app/public /app diff --git a/build.js b/build.js new file mode 100755 index 0000000..ca338c7 --- /dev/null +++ b/build.js @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +const esbuild = require('esbuild') +const alias = require('esbuild-plugin-alias') +const nodeGlobals = require('@esbuild-plugins/node-globals-polyfill').default + +const prod = process.argv.indexOf('prod') !== -1 + +esbuild + .build({ + bundle: true, + entryPoints: ['main.js'], + outdir: 'public', + plugins: [ + alias({ + stream: require.resolve('readable-stream') + }), + nodeGlobals({buffer: true}) + ], + sourcemap: prod ? false : 'inline', + define: { + window: 'self', + global: 'self' + } + }) + .then(() => console.log('build success.')) diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf index d6dee16..1adeb10 100644 --- a/nginx/conf.d/default.conf +++ b/nginx/conf.d/default.conf @@ -1,10 +1,6 @@ server { listen 80; - root /app; - include mime.types; - types { - application/wasm wasm; - } + root /app/public; location / { index index.html; diff --git a/package.json b/package.json index ca4c9c9..068d1ed 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "dependencies": { + "@esbuild-plugins/node-globals-polyfill": "^0.1.1", "buffer": "^6.0.3", - "nostr-tools": "^0.12.4", + "esbuild": "^0.14.21", + "esbuild-plugin-alias": "^0.2.1", + "events": "^3.3.0", + "nostr-tools": "^0.22.1", "readable-stream": "^3.6.0", "vue": "3" }, - "devDependencies": { - "webpack": "^5.65.0", - "webpack-cli": "^4.9.1" - }, + "devDependencies": {}, "scripts": { - "build": "mkdir -p dist/ && cp index.html dist/ && webpack" + "build": "./build.js prod", + "watch": "ag -l --js | entr ./build.js" } } diff --git a/index.html b/public/index.html similarity index 80% rename from index.html rename to public/index.html index c637851..af3f368 100644 --- a/index.html +++ b/public/index.html @@ -5,4 +5,4 @@
- + diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 81e2840..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const path = require('path') -const HtmlWebpackPlugin = require('html-webpack-plugin') - -module.exports = { - mode: 'development', - entry: './main.js', - output: { - path: `${__dirname}/dist`, - filename: 'out.js' - }, - experiments: {asyncWebAssembly: true}, - resolve: { - alias: { - stream: 'readable-stream' - }, - fallback: { - buffer: 'buffer/index.js', - stream: 'readable-stream/readable.js', - crypto: false - } - } -}