Support Svelte 3

fixes #546, #551, #552, #554
This commit is contained in:
Rich Harris
2019-02-03 14:29:47 -05:00
committed by GitHub
parent 83c8d7f855
commit ca034d0857
139 changed files with 1946 additions and 2016 deletions

View File

@@ -22,10 +22,7 @@ export default {
emitCss: true
}),
resolve()
],
// temporary, pending Rollup 1.0
experimentalCodeSplitting: true
]
},
server: {
@@ -44,10 +41,7 @@ export default {
preferBuiltins: true
})
],
external: ['sirv', 'polka'],
// temporary, pending Rollup 1.0
experimentalCodeSplitting: true
external: ['sirv', 'polka']
},
serviceworker: {

View File

@@ -1,4 +1,4 @@
import * as sapper from '../__sapper__/client.js';
import * as sapper from '@sapper/app';
window.start = () => sapper.start({
target: document.querySelector('#sapper')

View File

@@ -1,15 +1,20 @@
{#if preloading}
<script context="module">
export function preload() {
return {
rootPreloadFunctionRan: true
};
}
</script>
<script>
import { preloading } from '@sapper/app';
export let child;
export let rootPreloadFunctionRan;
</script>
{#if $preloading}
<progress class='preloading-progress' value=0.5/>
{/if}
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>
<script>
export default {
preload() {
return {
rootPreloadFunctionRan: true
};
}
};
</script>
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>

View File

@@ -1 +1,5 @@
<h1>{params.slug}</h1>
<script>
import { page } from '@sapper/app';
</script>
<h1>{$page.params.slug}</h1>

View File

@@ -1,17 +1,19 @@
<h1>{foo.bar()}</h1>
<script context="module">
export function preload() {
class Foo {
bar() {
return 42;
}
}
return {
foo: new Foo()
};
}
</script>
<script>
export default {
preload() {
class Foo {
bar() {
return 42;
}
}
export let foo;
</script>
return {
foo: new Foo()
};
}
};
</script>
<h1>{foo.bar()}</h1>

View File

@@ -1,11 +1,13 @@
<h1>{set.has('x')}</h1>
<script context="module">
export function preload() {
return {
set: new Set(['x'])
};
}
</script>
<script>
export default {
preload() {
return {
set: new Set(['x'])
};
}
};
</script>
export let set;
</script>
<h1>{set.has('x')}</h1>

View File

@@ -1,15 +1,13 @@
<h1>This page should never render</h1>
<script context="module">
export function preload() {
return new Promise(fulfil => {
if (typeof window !== 'undefined') {
window.fulfil = fulfil;
} else {
fulfil({});
}
});
}
</script>
<script>
export default {
preload() {
return new Promise(fulfil => {
if (typeof window !== 'undefined') {
window.fulfil = fulfil;
} else {
fulfil({});
}
});
}
};
</script>
<h1>This page should never render</h1>

View File

@@ -1,5 +1,5 @@
import polka from 'polka';
import * as sapper from '../__sapper__/server.js';
import * as sapper from '@sapper/server';
const { PORT } = process.env;

View File

@@ -1,10 +1,10 @@
import { timestamp, files, shell, routes } from '../__sapper__/service-worker.js';
import * as sapper from '@sapper/service-worker';
const ASSETS = `cache${timestamp}`;
const ASSETS = `cache${sapper.timestamp}`;
// `shell` is an array of all the files generated by webpack,
// `files` is an array of everything in the `static` directory
const to_cache = shell.concat(ASSETS);
const to_cache = sapper.shell.concat(sapper.files);
const cached = new Set(to_cache);
self.addEventListener('install', event => {
@@ -65,7 +65,7 @@ self.addEventListener('fetch', event => {
// might prefer a cache-first approach to a network-first one.)
event.respondWith(
caches
.open(`offline${timestamp}`)
.open(`offline${sapper.timestamp}`)
.then(async cache => {
try {
const response = await fetch(event.request);

View File

@@ -1,4 +1,3 @@
import * as path from 'path';
import * as assert from 'assert';
import * as puppeteer from 'puppeteer';
import { build } from '../../../api';
@@ -17,19 +16,18 @@ describe('preloading', function() {
// helpers
let start: () => Promise<void>;
let prefetchRoutes: () => Promise<void>;
let title: () => Promise<string>;
// hooks
before(async () => {
await build({ cwd: __dirname });
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
({ base, page, start, prefetchRoutes } = await runner.start());
({ base, page, start, prefetchRoutes, title } = await runner.start());
});
after(() => runner.end());
const title = () => page.$eval('h1', node => node.textContent);
it('serializes Set objects returned from preload', async () => {
await page.goto(`${base}/preload-values/set`);