mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
update tests
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@ node_modules
|
||||
cypress/screenshots
|
||||
test/app/.sapper
|
||||
test/app/src/manifest
|
||||
__sapper__
|
||||
test/app/export
|
||||
test/app/build
|
||||
sapper
|
||||
|
||||
1
index.js
Normal file
1
index.js
Normal file
@@ -0,0 +1 @@
|
||||
throw new Error(`As of Sapper 0.22, you should not import 'sapper' directly. See https://sapper.svelte.technology/guide#0-21-to-0-22 for more information`);
|
||||
@@ -1 +0,0 @@
|
||||
This directory exists for legacy reasons and should be deleted before releasing version 1.
|
||||
@@ -1,2 +0,0 @@
|
||||
console.error('sapper/runtime/app.js has been deprecated in favour of sapper/runtime.js');
|
||||
export * from '../runtime.js';
|
||||
@@ -73,24 +73,30 @@ function generate_client(
|
||||
const server_routes_to_ignore = manifest_data.server_routes.filter(route =>
|
||||
!page_ids.has(route.pattern.toString()));
|
||||
|
||||
const component_indexes: Record<string, number> = {};
|
||||
|
||||
let code = `
|
||||
import root from ${stringify(get_file(path_to_routes, manifest_data.root))};
|
||||
import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};
|
||||
|
||||
const d = decodeURIComponent;
|
||||
|
||||
${manifest_data.components.map(component => {
|
||||
const components = [
|
||||
${manifest_data.components.map((component, i) => {
|
||||
const annotation = bundler === 'webpack'
|
||||
? `/* webpackChunkName: "${component.name}" */ `
|
||||
: '';
|
||||
|
||||
const source = get_file(path_to_routes, component);
|
||||
|
||||
return `const ${component.name} = {
|
||||
component_indexes[component.name] = i;
|
||||
|
||||
return `{
|
||||
js: () => import(${annotation}${stringify(source)}),
|
||||
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
|
||||
};`;
|
||||
}).join('\n')}
|
||||
}`;
|
||||
}).join(',\n\t\t\t')}
|
||||
];
|
||||
|
||||
const manifest = {
|
||||
ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}],
|
||||
@@ -105,10 +111,10 @@ function generate_client(
|
||||
|
||||
if (part.params.length > 0) {
|
||||
const props = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
|
||||
return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`;
|
||||
return `{ component: components[${component_indexes[part.component.name]}], params: match => ({ ${props.join(', ')} }) }`;
|
||||
}
|
||||
|
||||
return `{ component: ${part.component.name} }`;
|
||||
return `{ component: components[${component_indexes[part.component.name]}] }`;
|
||||
}).join(',\n\t\t\t\t\t\t')}
|
||||
]
|
||||
}`).join(',\n\n\t\t\t\t')}
|
||||
@@ -144,9 +150,9 @@ function generate_server(
|
||||
|
||||
const imports = [].concat(
|
||||
manifest_data.server_routes.map(route =>
|
||||
`import * as ${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
|
||||
`import * as __${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
|
||||
manifest_data.components.map(component =>
|
||||
`import ${component.name} from ${stringify(get_file(path_to_routes, component))};`),
|
||||
`import __${component.name} from ${stringify(get_file(path_to_routes, component))};`),
|
||||
`import root from ${stringify(get_file(path_to_routes, manifest_data.root))};`,
|
||||
`import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
|
||||
);
|
||||
@@ -161,7 +167,7 @@ function generate_server(
|
||||
${manifest_data.server_routes.map(route => `{
|
||||
// ${route.file}
|
||||
pattern: ${route.pattern},
|
||||
handlers: ${route.name},
|
||||
handlers: __${route.name},
|
||||
params: ${route.params.length > 0
|
||||
? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })`
|
||||
: `() => ({})`}
|
||||
@@ -179,7 +185,7 @@ function generate_server(
|
||||
const props = [
|
||||
`name: "${part.component.name}"`,
|
||||
`file: ${stringify(part.component.file)}`,
|
||||
`component: ${part.component.name}`
|
||||
`component: __${part.component.name}`
|
||||
];
|
||||
|
||||
if (part.params.length > 0) {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { init, goto, prefetchRoutes } from '../../../runtime.js';
|
||||
import { Store } from 'svelte/store.js';
|
||||
import { manifest } from './manifest/client.js';
|
||||
import * as sapper from './__sapper__/client.js';
|
||||
|
||||
window.init = () => {
|
||||
return init({
|
||||
return sapper.start({
|
||||
target: document.querySelector('#sapper'),
|
||||
manifest,
|
||||
store: data => new Store(data)
|
||||
});
|
||||
};
|
||||
|
||||
window.prefetchRoutes = prefetchRoutes;
|
||||
window.goto = goto;
|
||||
window.prefetchRoutes = sapper.prefetchRoutes;
|
||||
window.goto = sapper.goto;
|
||||
@@ -9,17 +9,9 @@
|
||||
<button class='prefetch' on:click='prefetch("blog/why-the-name")'>Why the name?</button>
|
||||
|
||||
<script>
|
||||
import { goto, prefetch } from '../../../../runtime.js';
|
||||
import { prefetch } from '../__sapper__/client.js';
|
||||
|
||||
export default {
|
||||
oncreate() {
|
||||
window.goto = goto;
|
||||
},
|
||||
|
||||
ondestroy() {
|
||||
window.goto = null;
|
||||
},
|
||||
|
||||
methods: {
|
||||
prefetch
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@ import fs from 'fs';
|
||||
import { resolve } from 'url';
|
||||
import express from 'express';
|
||||
import serve from 'serve-static';
|
||||
import sapper from '../../../dist/middleware.js';
|
||||
import { Store } from 'svelte/store.js';
|
||||
import { manifest } from './manifest/server.js';
|
||||
import * as sapper from './__sapper__/server.js';
|
||||
|
||||
let pending;
|
||||
let ended;
|
||||
@@ -92,8 +91,7 @@ const middlewares = [
|
||||
next();
|
||||
},
|
||||
|
||||
sapper({
|
||||
manifest,
|
||||
sapper.middleware({
|
||||
store: (req, res) => {
|
||||
return new Store({
|
||||
title: `${req.hello} ${res.locals.name}`
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { assets, shell, timestamp, routes } from './manifest/service-worker.js';
|
||||
import { files, shell, timestamp, routes } from './__sapper__/service-worker.js';
|
||||
|
||||
const ASSETS = `cachetimestamp`;
|
||||
|
||||
// `shell` is an array of all the files generated by webpack,
|
||||
// `assets` is an array of everything in the `assets` directory
|
||||
const to_cache = shell.concat(assets);
|
||||
const to_cache = shell.concat(files);
|
||||
const cached = new Set(to_cache);
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
|
||||
@@ -29,6 +29,9 @@ module.exports = {
|
||||
]
|
||||
},
|
||||
mode,
|
||||
optimization: {
|
||||
minimize: false
|
||||
},
|
||||
plugins: [
|
||||
isDev && new webpack.HotModuleReplacementPlugin()
|
||||
].filter(Boolean),
|
||||
@@ -64,6 +67,9 @@ module.exports = {
|
||||
]
|
||||
},
|
||||
mode,
|
||||
optimization: {
|
||||
minimize: false
|
||||
},
|
||||
performance: {
|
||||
hints: false // it doesn't matter if server.js is large
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user