mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2dc246398b | ||
|
|
b7ac067459 | ||
|
|
8b50ff34b8 | ||
|
|
62abdb2a87 |
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# sapper changelog
|
||||
|
||||
## 0.1.0
|
||||
|
||||
* First public preview
|
||||
@@ -11,6 +11,4 @@ exports.dest = path.resolve(
|
||||
process.env.SAPPER_DEST || '.sapper'
|
||||
);
|
||||
|
||||
exports.main_built = path.resolve('templates/.main.tmp.js');
|
||||
|
||||
exports.server_routes = path.resolve(exports.dest, 'server-routes.js');
|
||||
19
lib/index.js
19
lib/index.js
@@ -94,7 +94,7 @@ module.exports = function connect(opts) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handle_route(url, req, res) {
|
||||
async function handle_route(url, req, res, next) {
|
||||
// whatever happens, we're going to serve some HTML
|
||||
res.set({
|
||||
'Content-Type': 'text/html'
|
||||
@@ -128,20 +128,7 @@ module.exports = function connect(opts) {
|
||||
|
||||
else {
|
||||
const handler = mod[req.method.toLowerCase()];
|
||||
if (handler) {
|
||||
if (handler.length === 2) {
|
||||
handler(req, res);
|
||||
} else {
|
||||
const data = await handler(req);
|
||||
|
||||
// TODO headers, error handling
|
||||
if (typeof data === 'string') {
|
||||
res.end(data);
|
||||
} else {
|
||||
res.end(JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (handler) handler(req, res, next);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -170,7 +157,7 @@ module.exports = function connect(opts) {
|
||||
handle_index(url, req, res, () => {
|
||||
handle_service_worker(url, req, res, () => {
|
||||
handle_webpack_generated_files(url, req, res, () => {
|
||||
handle_route(url, req, res);
|
||||
handle_route(url, req, res, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { dest, main_built, server_routes, dev } = require('../config.js');
|
||||
const { dest, server_routes, dev } = require('../config.js');
|
||||
|
||||
module.exports = function create_app(src, dest, routes, options) {
|
||||
function create_client_main() {
|
||||
@@ -23,11 +23,13 @@ module.exports = function create_app(src, dest, routes, options) {
|
||||
.replace(/__routes__/g, code)
|
||||
.replace(/__dev__/g, String(dev));
|
||||
|
||||
fs.writeFileSync(main_built, main);
|
||||
const file = path.resolve(dest, 'main.js');
|
||||
|
||||
fs.writeFileSync(file, main);
|
||||
|
||||
// need to fudge the mtime, because webpack is soft in the head
|
||||
const stats = fs.statSync(main_built);
|
||||
fs.utimesSync(main_built, stats.atimeMs - 999999, stats.mtimeMs - 999999);
|
||||
const stats = fs.statSync(file);
|
||||
fs.utimesSync(file, stats.atimeMs - 999999, stats.mtimeMs - 999999);
|
||||
}
|
||||
|
||||
function create_server_routes() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.0.22",
|
||||
"description": "Combat-ready apps, engineered by Svelte",
|
||||
"version": "0.1.0",
|
||||
"description": "Military-grade apps, engineered by Svelte",
|
||||
"main": "lib/index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
||||
@@ -2,7 +2,7 @@ const detach = node => {
|
||||
node.parentNode.removeChild(node);
|
||||
};
|
||||
|
||||
let component;
|
||||
export let component;
|
||||
let target;
|
||||
let routes;
|
||||
|
||||
@@ -158,28 +158,26 @@ function findAnchor(node) {
|
||||
|
||||
let inited;
|
||||
|
||||
const app = {
|
||||
init(_target, _routes) {
|
||||
target = _target;
|
||||
routes = _routes;
|
||||
export function init(_target, _routes) {
|
||||
target = _target;
|
||||
routes = _routes;
|
||||
|
||||
if (!inited) { // this check makes HMR possible
|
||||
window.addEventListener('click', handle_click);
|
||||
window.addEventListener('popstate', handle_popstate);
|
||||
if (!inited) { // this check makes HMR possible
|
||||
window.addEventListener('click', handle_click);
|
||||
window.addEventListener('popstate', handle_popstate);
|
||||
|
||||
// prefetch
|
||||
window.addEventListener('touchstart', prefetch);
|
||||
window.addEventListener('mouseover', prefetch);
|
||||
// prefetch
|
||||
window.addEventListener('touchstart', prefetch);
|
||||
window.addEventListener('mouseover', prefetch);
|
||||
|
||||
inited = true;
|
||||
}
|
||||
|
||||
const scroll = scroll_history[uid] = scroll_state();
|
||||
|
||||
history.replaceState({ id: uid }, '', window.location.href);
|
||||
navigate(new URL(window.location), uid);
|
||||
inited = true;
|
||||
}
|
||||
};
|
||||
|
||||
const scroll = scroll_history[uid] = scroll_state();
|
||||
|
||||
history.replaceState({ id: uid }, '', window.location.href);
|
||||
navigate(new URL(window.location), uid);
|
||||
}
|
||||
|
||||
function which(event) {
|
||||
event = event || window.event;
|
||||
@@ -191,6 +189,4 @@ function scroll_state() {
|
||||
x: window.scrollX,
|
||||
y: window.scrollY
|
||||
};
|
||||
}
|
||||
|
||||
export default app;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
const path = require('path');
|
||||
const route_manager = require('../lib/route_manager.js');
|
||||
const { src, dest, dev, main_built, server_routes } = require('../lib/config.js');
|
||||
const { src, dest, dev, server_routes } = require('../lib/config.js');
|
||||
|
||||
module.exports = {
|
||||
dev,
|
||||
@@ -8,7 +8,7 @@ module.exports = {
|
||||
client: {
|
||||
entry: () => {
|
||||
return {
|
||||
main: main_built
|
||||
main: `${dest}/main.js`
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user