mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
Merge pull request #152 from sveltejs/gh-148
various improvements to manifest generation - fixes #148
This commit is contained in:
@@ -86,22 +86,23 @@ export default async function dev() {
|
||||
// TODO watch the configs themselves?
|
||||
const compilers = create_compilers();
|
||||
|
||||
function watch_files(pattern: string, callback: () => void) {
|
||||
function watch_files(pattern: string, events: string[], callback: () => void) {
|
||||
const watcher = chokidar.watch(pattern, {
|
||||
persistent: false
|
||||
persistent: true,
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
watcher.on('add', callback);
|
||||
watcher.on('change', callback);
|
||||
watcher.on('unlink', callback);
|
||||
events.forEach(event => {
|
||||
watcher.on(event, callback);
|
||||
});
|
||||
}
|
||||
|
||||
watch_files('routes/**/*.+(html|js|mjs)', () => {
|
||||
watch_files('routes/**/*', ['add', 'unlink'], () => {
|
||||
const routes = create_routes();
|
||||
create_app({ routes, dev_port });
|
||||
});
|
||||
|
||||
watch_files('app/template.html', () => {
|
||||
watch_files('app/template.html', ['change'], () => {
|
||||
const template = create_template();
|
||||
// TODO reload current page?
|
||||
});
|
||||
|
||||
@@ -6,14 +6,28 @@ import { fudge_mtime, posixify, write } from './utils';
|
||||
import { dev } from '../config';
|
||||
import { Route } from '../interfaces';
|
||||
|
||||
// in dev mode, we avoid touching the fs unnecessarily
|
||||
let last_client_manifest: string = null;
|
||||
let last_server_manifest: string = null;
|
||||
|
||||
export default function create_app({ routes, dev_port }: {
|
||||
routes: Route[];
|
||||
dev_port: number;
|
||||
}) {
|
||||
mkdirp.sync('app/manifest');
|
||||
|
||||
write('app/manifest/client.js', generate_client(routes, dev_port));
|
||||
write('app/manifest/server.js', generate_server(routes));
|
||||
const client_manifest = generate_client(routes, dev_port);
|
||||
const server_manifest = generate_server(routes);
|
||||
|
||||
if (client_manifest !== last_client_manifest) {
|
||||
write(`app/manifest/client.js`, client_manifest);
|
||||
last_client_manifest = client_manifest;
|
||||
}
|
||||
|
||||
if (server_manifest !== last_server_manifest) {
|
||||
write(`app/manifest/server.js`, server_manifest);
|
||||
last_server_manifest = server_manifest;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_client(routes: Route[], dev_port?: number) {
|
||||
|
||||
Reference in New Issue
Block a user