mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 04:44:35 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd1f2d79ff | ||
|
|
dccd3cdeb0 | ||
|
|
b3b5d9f352 | ||
|
|
10ddaeb7a3 | ||
|
|
060f9b2f5e | ||
|
|
32dfa94247 | ||
|
|
797cc3cde1 |
11
connect.js
11
connect.js
@@ -1,5 +1,3 @@
|
|||||||
require('svelte/ssr/register');
|
|
||||||
const esm = require('@std/esm');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
@@ -12,10 +10,6 @@ const create_compiler = require('./lib/utils/create_compiler.js');
|
|||||||
const escape_html = require('escape-html');
|
const escape_html = require('escape-html');
|
||||||
const { src, dest, dev } = require('./lib/config.js');
|
const { src, dest, dev } = require('./lib/config.js');
|
||||||
|
|
||||||
const esmRequire = esm(module, {
|
|
||||||
esm: 'js'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = function connect(opts) {
|
module.exports = function connect(opts) {
|
||||||
mkdirp(dest);
|
mkdirp(dest);
|
||||||
rimraf.sync(path.join(dest, '**/*'));
|
rimraf.sync(path.join(dest, '**/*'));
|
||||||
@@ -125,9 +119,10 @@ module.exports = function connect(opts) {
|
|||||||
}));
|
}));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
res.status(500).end(templates.render(500, {
|
res.status(500).end(templates.render(500, {
|
||||||
title: err.name || 'Internal server error',
|
title: (err && err.name) || 'Internal server error',
|
||||||
url,
|
url,
|
||||||
error: escape_html(err.details || err.message || err || 'Unknown error')
|
error: escape_html(err && (err.details || err.message || err) || 'Unknown error'),
|
||||||
|
stack: err && err.stack.split('\n').slice(1).join('\n')
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ module.exports = function create_webpack_compiler(dest, routes, dev) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
const assets = glob.sync('**', { cwd: 'assets' });
|
const assets = glob.sync('**', { cwd: 'assets', nodir: true });
|
||||||
|
|
||||||
const route_code = `[${
|
const route_code = `[${
|
||||||
routes
|
routes
|
||||||
|
|||||||
21
package-lock.json
generated
21
package-lock.json
generated
@@ -1,14 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.0.9",
|
"version": "0.0.20",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@std/esm": {
|
|
||||||
"version": "0.18.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@std/esm/-/esm-0.18.0.tgz",
|
|
||||||
"integrity": "sha512-oeHSSVp/WxC08ngpKgyYR4LcI0+EBwZiJcB58jvIqyJnOGxudSkxTgAQKsVfpNsMXfOoILgu9PWhuzIZ8GQEjw=="
|
|
||||||
},
|
|
||||||
"acorn": {
|
"acorn": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz",
|
||||||
@@ -499,9 +494,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errno": {
|
"errno": {
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.6.tgz",
|
||||||
"integrity": "sha512-tv2H+e3KBnMmNRuoVG24uorOj3XfYo+/nJJd07PUISRr0kaMKQKL5kyD+6ANXk1ZIIsvbORsjvHnCfC4KIc7uQ==",
|
"integrity": "sha512-IsORQDpaaSwcDP4ZZnHxgE85werpo34VYn1Ud3mq+eUsF593faR8oCZNXrROVkpFu2TsbrNhHin0aUrTsQ9vNw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"prr": "1.0.1"
|
"prr": "1.0.1"
|
||||||
}
|
}
|
||||||
@@ -1879,7 +1874,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz",
|
||||||
"integrity": "sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=",
|
"integrity": "sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"errno": "0.1.5",
|
"errno": "0.1.6",
|
||||||
"readable-stream": "2.3.3"
|
"readable-stream": "2.3.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2559,12 +2554,6 @@
|
|||||||
"has-flag": "2.0.0"
|
"has-flag": "2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"svelte": {
|
|
||||||
"version": "1.47.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-1.47.1.tgz",
|
|
||||||
"integrity": "sha512-xRw4pjF19XKfeTxp+TOTE/MQmRS7tRzm0hhh0dr/nc3NuHBfCBXnfve0ZymF8tZ+J/WM0cqfZ83RxZid2zf7qA==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"tapable": {
|
"tapable": {
|
||||||
"version": "0.2.8",
|
"version": "0.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.8.tgz",
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -1,24 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.0.20",
|
"version": "0.0.21",
|
||||||
"description": "Combat-ready apps, engineered by Svelte",
|
"description": "Combat-ready apps, engineered by Svelte",
|
||||||
"main": "connect.js",
|
"main": "connect.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@std/esm": "^0.18.0",
|
|
||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"webpack": "^3.10.0"
|
"webpack": "^3.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "^4.0.1",
|
"mocha": "^4.0.1"
|
||||||
"svelte": "^1.47.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"svelte": "^1.47.1"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --opts mocha.opts"
|
"test": "mocha --opts mocha.opts"
|
||||||
@@ -36,8 +31,5 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/sveltejs/sapper/issues"
|
"url": "https://github.com/sveltejs/sapper/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/sveltejs/sapper#readme",
|
"homepage": "https://github.com/sveltejs/sapper#readme"
|
||||||
"@std/esm": {
|
|
||||||
"esm": "js"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ const scroll_history = {};
|
|||||||
let uid = 1;
|
let uid = 1;
|
||||||
let cid;
|
let cid;
|
||||||
|
|
||||||
window.scroll_history = scroll_history;
|
|
||||||
|
|
||||||
if ('scrollRestoration' in history) {
|
if ('scrollRestoration' in history) {
|
||||||
history.scrollRestoration = 'manual'
|
history.scrollRestoration = 'manual'
|
||||||
}
|
}
|
||||||
@@ -59,7 +57,9 @@ const app = {
|
|||||||
hydrate: !!component
|
hydrate: !!component
|
||||||
});
|
});
|
||||||
|
|
||||||
window.scrollTo(scroll.x, scroll.y);
|
if (scroll) {
|
||||||
|
window.scrollTo(scroll.x, scroll.y);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +108,11 @@ const app = {
|
|||||||
const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString';
|
const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString';
|
||||||
const href = svg ? a.href.baseVal : a.href;
|
const href = svg ? a.href.baseVal : a.href;
|
||||||
|
|
||||||
|
if (href === window.location.href) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore if tag has
|
// Ignore if tag has
|
||||||
// 1. 'download' attribute
|
// 1. 'download' attribute
|
||||||
// 2. rel='external' attribute
|
// 2. rel='external' attribute
|
||||||
@@ -116,9 +121,12 @@ const app = {
|
|||||||
// Ignore if <a> has a target
|
// Ignore if <a> has a target
|
||||||
if (svg ? a.target.baseVal : a.target) return;
|
if (svg ? a.target.baseVal : a.target) return;
|
||||||
|
|
||||||
const scroll = scroll_state();
|
const url = new URL(href);
|
||||||
|
|
||||||
if (navigate(new URL(a.href), null)) {
|
// Don't handle hash changes
|
||||||
|
if (url.pathname === window.location.pathname && url.search === window.location.search) return;
|
||||||
|
|
||||||
|
if (navigate(url, null)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -140,10 +148,15 @@ const app = {
|
|||||||
window.addEventListener('mouseover', preload);
|
window.addEventListener('mouseover', preload);
|
||||||
|
|
||||||
window.addEventListener('popstate', event => {
|
window.addEventListener('popstate', event => {
|
||||||
if (!event.state) return; // hashchange, or otherwise outside sapper's control
|
|
||||||
scroll_history[cid] = scroll_state();
|
scroll_history[cid] = scroll_state();
|
||||||
|
|
||||||
navigate(new URL(window.location), event.state.id);
|
if (event.state) {
|
||||||
|
navigate(new URL(window.location), event.state.id);
|
||||||
|
} else {
|
||||||
|
// hashchange
|
||||||
|
cid = ++uid;
|
||||||
|
history.replaceState({ id: cid }, '', window.location.href);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const scroll = scroll_history[uid] = scroll_state();
|
const scroll = scroll_history[uid] = scroll_state();
|
||||||
|
|||||||
Reference in New Issue
Block a user