Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit ff3b434

Browse files
authored
Merge pull request #152 from sveltejs/gh-148
various improvements to manifest generation - fixes #148
2 parents 7625302 + 2622692 commit ff3b434

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/cli/dev.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,23 @@ export default async function dev() {
8686
// TODO watch the configs themselves?
8787
const compilers = create_compilers();
8888

89-
function watch_files(pattern: string, callback: () => void) {
89+
function watch_files(pattern: string, events: string[], callback: () => void) {
9090
const watcher = chokidar.watch(pattern, {
91-
persistent: false
91+
persistent: true,
92+
ignoreInitial: true
9293
});
9394

94-
watcher.on('add', callback);
95-
watcher.on('change', callback);
96-
watcher.on('unlink', callback);
95+
events.forEach(event => {
96+
watcher.on(event, callback);
97+
});
9798
}
9899

99-
watch_files('routes/**/*.+(html|js|mjs)', () => {
100+
watch_files('routes/**/*', ['add', 'unlink'], () => {
100101
const routes = create_routes();
101102
create_app({ routes, dev_port });
102103
});
103104

104-
watch_files('app/template.html', () => {
105+
watch_files('app/template.html', ['change'], () => {
105106
const template = create_template();
106107
// TODO reload current page?
107108
});

src/core/create_app.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@ import { fudge_mtime, posixify, write } from './utils';
66
import { dev } from '../config';
77
import { Route } from '../interfaces';
88

9+
// in dev mode, we avoid touching the fs unnecessarily
10+
let last_client_manifest: string = null;
11+
let last_server_manifest: string = null;
12+
913
export default function create_app({ routes, dev_port }: {
1014
routes: Route[];
1115
dev_port: number;
1216
}) {
1317
mkdirp.sync('app/manifest');
1418

15-
write('app/manifest/client.js', generate_client(routes, dev_port));
16-
write('app/manifest/server.js', generate_server(routes));
19+
const client_manifest = generate_client(routes, dev_port);
20+
const server_manifest = generate_server(routes);
21+
22+
if (client_manifest !== last_client_manifest) {
23+
write(`app/manifest/client.js`, client_manifest);
24+
last_client_manifest = client_manifest;
25+
}
26+
27+
if (server_manifest !== last_server_manifest) {
28+
write(`app/manifest/server.js`, server_manifest);
29+
last_server_manifest = server_manifest;
30+
}
1731
}
1832

1933
function generate_client(routes: Route[], dev_port?: number) {

0 commit comments

Comments
 (0)