Skip to content

Commit

Permalink
update sapper example
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Dec 24, 2021
1 parent 5290e62 commit 1992961
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 34 deletions.
4 changes: 3 additions & 1 deletion examples/sapper-app-template-web3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

The default template for setting up a [Sapper](https://github.com/sveltejs/sapper) project. Can use either Rollup or webpack as bundler.

## Please note

## Getting started
Sapper is no longer being actively developed. You may be interested in using Sapper's succesor, [SvelteKit](https://kit.svelte.dev/) for new projects.

## Getting started

### Using `degit`

Expand Down
10 changes: 5 additions & 5 deletions examples/sapper-app-template-web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"dependencies": {
"compression": "^1.7.1",
"polka": "next",
"sirv": "^1.0.0",
"svelte-web3": "^1.3.4"
"sirv": "^1.0.0"
},
"devDependencies": {
"file-loader": "^6.0.0",
"svelte-web3": "file:../../",
"sapper": "^0.28.0",
"svelte": "^3.17.3",
"svelte-loader": "^2.9.0",
"webpack": "^4.7.0",
"file-loader": "^6.0.0",
"svelte-loader": "^3.0.0",
"webpack": "^4.46.0",
"webpack-modules": "^1.0.0"
}
}
8 changes: 3 additions & 5 deletions examples/sapper-app-template-web3/scripts/setupTypeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,10 @@ function updateWebpackConfig() {
/entry: config\.serviceworker\.entry\(\)/,
`entry: { 'service-worker': config.serviceworker.entry()['service-worker'].replace(/\\.js$/, '.ts') }`
],
// Add preprocess to the svelte config, this is tricky because there's no easy signifier.
// Instead we look for 'hydratable: true,'
[
/hydratable: true(?!,\n\s*preprocess)/g,
'hydratable: true,\n\t\t\t\t\t\t\tpreprocess: sveltePreprocess({ sourceMap: dev })'
],
/loader: 'svelte-loader',\n\t\t\t\t\t\toptions: {/g,
'loader: \'svelte-loader\',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tpreprocess: sveltePreprocess({ sourceMap: dev }),'
],
// Add TypeScript rules for client and server
[
/module: {\n\s*rules: \[\n\s*(?!{\n\s*test: \/\\\.ts\$\/)/g,
Expand Down
12 changes: 6 additions & 6 deletions examples/sapper-app-template-web3/src/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
*/
declare module "*.gif" {
const value: string;
export = value;
export default value;
}

declare module "*.jpg" {
const value: string;
export = value;
export default value;
}

declare module "*.jpeg" {
const value: string;
export = value;
export default value;
}

declare module "*.png" {
const value: string;
export = value;
export default value;
}

declare module "*.svg" {
const value: string;
export = value;
export default value;
}

declare module "*.webp" {
const value: string;
export = value;
export default value;
}
14 changes: 7 additions & 7 deletions examples/sapper-app-template-web3/src/routes/web3test.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script>
import { onMount } from 'svelte';
import { ethStore, web3, selectedAccount, connected, chainId, chainData } from 'svelte-web3'
import { defaultEvmStores, web3, selectedAccount, connected, chainId, chainData } from 'svelte-web3'
export let message
export let tipAddress
const enable = () => ethStore.setProvider('https://sokol.poa.network')
const enableBrowser = () => ethStore.setBrowserProvider()
const enable = () => defaultEvmStores.setProvider('https://sokol.poa.network')
const enableBrowser = () => defaultEvmStores.setBrowserProvider()
$: checkAccount = $selectedAccount || '0x0000000000000000000000000000000000000000'
$: balance = $connected ? $web3.eth.getBalance(checkAccount) : ''
Expand All @@ -28,7 +28,7 @@
onMount(
async () => {
message = 'Connecting to Ethereum Testnet Görli...'
await ethStore.setProvider('https://rpc.slock.it/goerli')
await defaultEvmStores.setProvider('https://rpc.slock.it/goerli')
message = ''
})
Expand Down Expand Up @@ -77,11 +77,11 @@
<span>waiting...</span>
{:then value}
<span>{value}</span>
{/await} {$chainData.nativeCurrency?.symbol}
{/await} {$chainData.nativeCurrency.symbol}
</p>

{#if $selectedAccount}
<p><button on:click="{sendTip}">send 0.01 {$chainData.nativeCurrency?.symbol} tip to {tipAddress} (author)</button></p>
{#if false && $selectedAccount}
<p><button on:click="{sendTip}">send 0.01 {$chainData.nativeCurrency.symbol} tip to {tipAddress} (author)</button></p>
{/if}

{/if}
Expand Down
3 changes: 2 additions & 1 deletion examples/sapper-app-template-web3/src/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<link rel="stylesheet" href="global.css">
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
<link rel="icon" type="image/png" href="favicon.png">
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<link rel="apple-touch-icon" href="logo-192.png">
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

<!-- Sapper creates a <script> tag containing `src/client.js`
and anything else it needs to hydrate the app and
Expand Down
6 changes: 4 additions & 2 deletions examples/sapper-app-template-web3/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
{
"src": "logo-192.png",
"sizes": "192x192",
"type": "image/png"
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "logo-512.png",
"sizes": "512x512",
"type": "image/png"
"type": "image/png",
"purpose": "any maskable"
}
]
}
22 changes: 15 additions & 7 deletions examples/sapper-app-template-web3/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ module.exports = {
use: {
loader: 'svelte-loader',
options: {
dev,
hydratable: true,
hotReload: false // pending https://github.com/sveltejs/svelte/issues/2377
compilerOptions: {
dev,
hydratable: true
},
// Webpack 4 uses acorn v6 which doesn't work with HMR
// Use overrides from npm or resolutions from yarn to set minimal
// acorn version to v7+
// https://github.com/sveltejs/sapper-template/pull/308
hotReload: false
}
}
},
Expand Down Expand Up @@ -63,10 +69,12 @@ module.exports = {
use: {
loader: 'svelte-loader',
options: {
css: false,
generate: 'ssr',
hydratable: true,
dev
compilerOptions: {
css: false,
generate: 'ssr',
hydratable: true,
dev
},
}
}
},
Expand Down

0 comments on commit 1992961

Please sign in to comment.