-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sandwichfarm/alpha
Alpha
- Loading branch information
Showing
37 changed files
with
5,913 additions
and
3,692 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
tmp/ | ||
dist/ | ||
node_modules | ||
rust | ||
rust | ||
src/wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import getPort from 'get-port'; | ||
import esbuild from 'esbuild'; | ||
import { clean } from 'esbuild-plugin-clean'; | ||
import esbuildPluginTsc from 'esbuild-plugin-tsc'; | ||
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker'; | ||
import { polyfillNode } from 'esbuild-plugin-polyfill-node'; | ||
import { wasmLoader } from 'esbuild-plugin-wasm'; | ||
import copy from 'esbuild-plugin-copy'; | ||
import { minify } from 'terser'; | ||
|
||
import { handleWasmUrl } from './handleWasmUrl.cjs'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const production = process.env.NODE_ENV === 'production'; | ||
|
||
export async function buildWithWatch() { | ||
await fs.mkdir(path.resolve(__dirname, 'dist'), { recursive: true }); | ||
const watch = !production; | ||
const livereloadPort = await getPort({ port: 53100 }); | ||
|
||
const workerBuildOptions = { | ||
entryPoints: ['src/mine.worker.ts'], | ||
bundle: true, | ||
format: 'iife', | ||
platform: 'browser', | ||
target: ['esnext'], | ||
minify: true, | ||
plugins: [ | ||
handleWasmUrl, | ||
wasmLoader(), | ||
], | ||
loader: { | ||
'.ts': 'ts', | ||
'.js': 'js', | ||
'.wasm': 'file', | ||
}, | ||
define: { | ||
'import.meta.url': 'self.location.href', | ||
}, | ||
outdir: 'dist', | ||
write: true, | ||
}; | ||
|
||
let workerResult; | ||
try { | ||
workerResult = await esbuild.build(workerBuildOptions); | ||
} catch (error) { | ||
console.error('Worker build failed:', error); | ||
process.exit(1); | ||
} | ||
|
||
if (!workerResult || workerResult.errors?.length > 0) { | ||
console.error('Worker build output is missing or contains errors.'); | ||
process.exit(1); | ||
} | ||
|
||
const workerFilePath = path.resolve(__dirname, 'dist', 'mine.worker.js'); | ||
const workerCode = await fs.readFile(workerFilePath, 'utf8'); | ||
const minifiedWorkerCode = await minify(workerCode); | ||
|
||
if (minifiedWorkerCode.error) { | ||
console.error('Terser minification failed:', minifiedWorkerCode.error); | ||
process.exit(1); | ||
} | ||
|
||
await fs.writeFile(workerFilePath, minifiedWorkerCode.code); | ||
|
||
const distPath = path.resolve(__dirname, 'dist'); | ||
await fs.mkdir(distPath, { recursive: true }); | ||
|
||
const mainBuildOptions = { | ||
entryPoints: ['src/index.ts'], | ||
outdir: 'dist', | ||
bundle: true, | ||
splitting: true, | ||
format: 'esm', | ||
platform: 'browser', | ||
target: ['esnext'], | ||
sourcemap: true, | ||
minify: production, | ||
plugins: [ | ||
esbuildPluginTsc({ | ||
force: true, | ||
}), | ||
handleWasmUrl, | ||
inlineWorkerPlugin({ | ||
entryPoints: ['dist/mine.worker.js'], | ||
minify: true, | ||
target: 'esnext', | ||
format: 'iife', | ||
}), | ||
polyfillNode({ | ||
polyfills: { | ||
fs: false, | ||
path: false, | ||
util: true, | ||
assert: true, | ||
stream: true, | ||
os: true, | ||
}, | ||
}), | ||
copy({ | ||
assets: { | ||
from: '../node_modules/notemine/notemine_bg.wasm', | ||
to: 'dist', | ||
}, | ||
}), | ||
].filter(Boolean), | ||
loader: { | ||
'.ts': 'ts', | ||
'.js': 'js', | ||
'.wasm': 'file', | ||
}, | ||
define: { | ||
'import.meta.url': 'self.location.href', | ||
}, | ||
}; | ||
|
||
try { | ||
if (watch) { | ||
const mainContext = await esbuild.context(mainBuildOptions); | ||
await mainContext.watch(); | ||
} else { | ||
await esbuild.build(mainBuildOptions); | ||
} | ||
} catch (error) { | ||
console.error('Main build failed:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
buildWithWatch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"jsx-a11y/rule-name": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/node_modules/ | ||
/public/build/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# This repo is no longer maintained. Consider using `npm init vite` and selecting the `svelte` option or — if you want a full-fledged app framework — use [SvelteKit](https://kit.svelte.dev), the official application framework for Svelte. | ||
|
||
--- | ||
|
||
# svelte app | ||
|
||
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template. | ||
|
||
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): | ||
|
||
```bash | ||
npx degit sveltejs/template svelte-app | ||
cd svelte-app | ||
``` | ||
|
||
*Note that you will need to have [Node.js](https://nodejs.org) installed.* | ||
|
||
|
||
## Get started | ||
|
||
Install the dependencies... | ||
|
||
```bash | ||
cd svelte-app | ||
npm install | ||
``` | ||
|
||
...then start [Rollup](https://rollupjs.org): | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. | ||
|
||
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. | ||
|
||
If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. | ||
|
||
## Building and running in production mode | ||
|
||
To create an optimised version of the app: | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). | ||
|
||
|
||
## Single-page app mode | ||
|
||
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. | ||
|
||
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json: | ||
|
||
```js | ||
"start": "sirv public --single" | ||
``` | ||
|
||
## Using TypeScript | ||
|
||
This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: | ||
|
||
```bash | ||
node scripts/setupTypeScript.js | ||
``` | ||
|
||
Or remove the script via: | ||
|
||
```bash | ||
rm scripts/setupTypeScript.js | ||
``` | ||
|
||
If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte). | ||
|
||
## Deploying to the web | ||
|
||
### With [Vercel](https://vercel.com) | ||
|
||
Install `vercel` if you haven't already: | ||
|
||
```bash | ||
npm install -g vercel | ||
``` | ||
|
||
Then, from within your project folder: | ||
|
||
```bash | ||
cd public | ||
vercel deploy --name my-project | ||
``` | ||
|
||
### With [surge](https://surge.sh/) | ||
|
||
Install `surge` if you haven't already: | ||
|
||
```bash | ||
npm install -g surge | ||
``` | ||
|
||
Then, from within your project folder: | ||
|
||
```bash | ||
npm run build | ||
surge public my-project.surge.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@notemine/svelte-demo", | ||
"version": "0.1.0", | ||
"private": false, | ||
"type": "module", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w", | ||
"start": "sirv public --no-clear" | ||
}, | ||
"dependencies": { | ||
"@rollup/plugin-alias": "5.1.1", | ||
"@rollup/plugin-url": "8.0.2", | ||
"@rollup/plugin-wasm": "6.2.2", | ||
"nostr-tools": "2.7.2", | ||
"rollup-plugin-terser": "7.0.2", | ||
"rollup-plugin-typescript2": "0.36.0", | ||
"rollup-plugin-web-worker-loader": "1.6.1", | ||
"sirv-cli": "^2.0.0", | ||
"webpack-env": "0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "28.0.0", | ||
"@rollup/plugin-node-resolve": "15.3.0", | ||
"@rollup/plugin-terser": "^0.4.0", | ||
"rollup": "^3.15.0", | ||
"rollup-plugin-copy": "3.5.0", | ||
"rollup-plugin-css-only": "^4.3.0", | ||
"rollup-plugin-livereload": "^2.0.0", | ||
"rollup-plugin-postcss": "4.0.2", | ||
"rollup-plugin-svelte": "^7.1.2", | ||
"svelte": "^3.55.0", | ||
"svelte-preprocess": "6.0.2", | ||
"webpack": "5.94.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
html, body { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
color: #333; | ||
margin: 0; | ||
padding: 8px; | ||
box-sizing: border-box; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
} | ||
|
||
a { | ||
color: rgb(0,100,200); | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
text-decoration: underline; | ||
} | ||
|
||
a:visited { | ||
color: rgb(0,80,160); | ||
} | ||
|
||
label { | ||
display: block; | ||
} | ||
|
||
input, button, select, textarea { | ||
font-family: inherit; | ||
font-size: inherit; | ||
-webkit-padding: 0.4em 0; | ||
padding: 0.4em; | ||
margin: 0 0 0.5em 0; | ||
box-sizing: border-box; | ||
border: 1px solid #ccc; | ||
border-radius: 2px; | ||
} | ||
|
||
input:disabled { | ||
color: #ccc; | ||
} | ||
|
||
button { | ||
color: #333; | ||
background-color: #f4f4f4; | ||
outline: none; | ||
} | ||
|
||
button:disabled { | ||
color: #999; | ||
} | ||
|
||
button:not(:disabled):active { | ||
background-color: #ddd; | ||
} | ||
|
||
button:focus { | ||
border-color: #666; | ||
} |
Oops, something went wrong.