mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-14 20:14:39 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0cc877456 | ||
|
|
3ed9ce27a1 | ||
|
|
edba45b809 | ||
|
|
43c1890235 | ||
|
|
605929053c | ||
|
|
2752c73ebb | ||
|
|
2547db39ac |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
|||||||
# sapper changelog
|
# sapper changelog
|
||||||
|
|
||||||
|
## 0.7.3
|
||||||
|
|
||||||
|
* Handle webpack assets that are arrays instead of strings ([#131](https://github.com/sveltejs/sapper/pull/131))
|
||||||
|
* Wait for new server to start before broadcasting HMR update ([#129](https://github.com/sveltejs/sapper/pull/129))
|
||||||
|
|
||||||
|
## 0.7.2
|
||||||
|
|
||||||
|
* Add `hmr-client.js` to package
|
||||||
|
* Wait until first successful client build before creating service-worker.js
|
||||||
|
|
||||||
## 0.7.1
|
## 0.7.1
|
||||||
|
|
||||||
* Add missing `tslib` dependency
|
* Add missing `tslib` dependency
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
let source;
|
let source;
|
||||||
|
|
||||||
console.log('!!!! hmr client');
|
|
||||||
|
|
||||||
function check() {
|
function check() {
|
||||||
if (module.hot.status() === 'idle') {
|
if (module.hot.status() === 'idle') {
|
||||||
module.hot.check(true).then(modules => {
|
module.hot.check(true).then(modules => {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"description": "Military-grade apps, engineered by Svelte",
|
"description": "Military-grade apps, engineered by Svelte",
|
||||||
"main": "middleware.js",
|
"main": "middleware.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"middleware.js",
|
"middleware.js",
|
||||||
"runtime",
|
"runtime",
|
||||||
"runtime.js",
|
"runtime.js",
|
||||||
|
"hmr-client.js",
|
||||||
"webpack"
|
"webpack"
|
||||||
],
|
],
|
||||||
"directories": {
|
"directories": {
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
"code-frame": "^5.0.0",
|
"code-frame": "^5.0.0",
|
||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
|
"get-port": "^3.2.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
"locate-character": "^2.0.5",
|
"locate-character": "^2.0.5",
|
||||||
"mime": "^2.2.0",
|
"mime": "^2.2.0",
|
||||||
@@ -51,7 +53,6 @@
|
|||||||
"electron": "^1.8.2",
|
"electron": "^1.8.2",
|
||||||
"eslint": "^4.13.1",
|
"eslint": "^4.13.1",
|
||||||
"eslint-plugin-import": "^2.8.0",
|
"eslint-plugin-import": "^2.8.0",
|
||||||
"get-port": "^3.2.0",
|
|
||||||
"mocha": "^4.0.1",
|
"mocha": "^4.0.1",
|
||||||
"nightmare": "^2.10.0",
|
"nightmare": "^2.10.0",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
|
|||||||
@@ -137,14 +137,21 @@ export default async function dev(src: string, dir: string) {
|
|||||||
fs.writeFileSync(path.join(dir, 'server_info.json'), JSON.stringify(server_info, null, ' '));
|
fs.writeFileSync(path.join(dir, 'server_info.json'), JSON.stringify(server_info, null, ' '));
|
||||||
|
|
||||||
deferreds.client.promise.then(() => {
|
deferreds.client.promise.then(() => {
|
||||||
if (proc) proc.kill();
|
function restart() {
|
||||||
|
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proc) {
|
||||||
|
proc.kill();
|
||||||
|
proc.on('exit', restart);
|
||||||
|
} else {
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
proc = child_process.fork(`${dir}/server.js`, [], {
|
proc = child_process.fork(`${dir}/server.js`, [], {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
env: Object.assign({}, process.env)
|
env: Object.assign({}, process.env)
|
||||||
});
|
});
|
||||||
|
|
||||||
wait_for_port(3000, deferreds.server.fulfil); // TODO control port
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -182,33 +189,41 @@ export default async function dev(src: string, dir: string) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return create_serviceworker({
|
create_serviceworker({
|
||||||
routes: create_routes({ src }),
|
routes: create_routes({ src }),
|
||||||
client_files,
|
client_files,
|
||||||
src
|
src
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch_serviceworker();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (compilers.serviceworker) {
|
let watch_serviceworker = compilers.serviceworker
|
||||||
compilers.serviceworker.plugin('invalid', (filename: string) => {
|
? function() {
|
||||||
times.serviceworker_start = Date.now();
|
watch_serviceworker = noop;
|
||||||
});
|
|
||||||
|
|
||||||
compilers.serviceworker.watch({}, (err: Error, stats: any) => {
|
compilers.serviceworker.plugin('invalid', (filename: string) => {
|
||||||
if (err) {
|
times.serviceworker_start = Date.now();
|
||||||
// TODO notify client
|
});
|
||||||
} else if (stats.hasErrors()) {
|
|
||||||
// print errors. TODO notify client
|
|
||||||
stats.toJson().errors.forEach((error: Error) => {
|
|
||||||
console.error(error); // TODO make this look nice
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(`built service worker in ${Date.now() - times.serviceworker_start}ms`); // TODO prettify
|
|
||||||
|
|
||||||
const serviceworker_info = stats.toJson();
|
compilers.serviceworker.watch({}, (err: Error, stats: any) => {
|
||||||
fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' '));
|
if (err) {
|
||||||
}
|
// TODO notify client
|
||||||
});
|
} else if (stats.hasErrors()) {
|
||||||
}
|
// print errors. TODO notify client
|
||||||
}
|
stats.toJson().errors.forEach((error: Error) => {
|
||||||
|
console.error(error); // TODO make this look nice
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`built service worker in ${Date.now() - times.serviceworker_start}ms`); // TODO prettify
|
||||||
|
|
||||||
|
const serviceworker_info = stats.toJson();
|
||||||
|
fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' '));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: noop;
|
||||||
|
}
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
@@ -41,7 +41,7 @@ function generate_client(routes: Route[], src: string, dev: boolean, dev_port?:
|
|||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
const hmr_client = posixify(
|
const hmr_client = posixify(
|
||||||
path.resolve(__dirname, 'src/hmr-client.js')
|
path.resolve(__dirname, 'hmr-client.js')
|
||||||
);
|
);
|
||||||
|
|
||||||
code += `
|
code += `
|
||||||
|
|||||||
@@ -122,7 +122,12 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
|
|||||||
|
|
||||||
// preload main.js and current route
|
// preload main.js and current route
|
||||||
// TODO detect other stuff we can preload? images, CSS, fonts?
|
// TODO detect other stuff we can preload? images, CSS, fonts?
|
||||||
res.setHeader('Link', `</client/${chunks.main}>;rel="preload";as="script", </client/${chunks[route.id]}>;rel="preload";as="script"`);
|
const link = []
|
||||||
|
.concat(chunks.main, chunks[route.id])
|
||||||
|
.map(file => `</client/${file}>;rel="preload";as="script"`)
|
||||||
|
.join(', ');
|
||||||
|
|
||||||
|
res.setHeader('Link', link);
|
||||||
|
|
||||||
const data = { params: req.params, query: req.query };
|
const data = { params: req.params, query: req.query };
|
||||||
|
|
||||||
@@ -159,7 +164,11 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
|
|||||||
|
|
||||||
const { html, head, css } = mod.render(data);
|
const { html, head, css } = mod.render(data);
|
||||||
|
|
||||||
let scripts = `<script src='/client/${chunks.main}'></script>`;
|
let scripts = []
|
||||||
|
.concat(chunks.main) // chunks main might be an array. it might not! thanks, webpack
|
||||||
|
.map(file => `<script src='/client/${file}'></script>`)
|
||||||
|
.join('');
|
||||||
|
|
||||||
scripts = `<script>__SAPPER__ = { preloaded: ${serialized} };</script>${scripts}`;
|
scripts = `<script>__SAPPER__ = { preloaded: ${serialized} };</script>${scripts}`;
|
||||||
|
|
||||||
const page = template.render({
|
const page = template.render({
|
||||||
|
|||||||
Reference in New Issue
Block a user