Compare commits

..

8 Commits

Author SHA1 Message Date
Rich Harris
c0cc877456 -> v0.7.3 2018-02-20 12:23:32 -05:00
Rich Harris
3ed9ce27a1 Merge pull request #131 from sveltejs/webpack-insanity
handle case where webpack asset is an array instead of a string
2018-02-20 12:18:29 -05:00
Rich Harris
edba45b809 Merge pull request #129 from sveltejs/robustify-hmr
ensure old server is killed before listening for port on new server
2018-02-20 12:18:10 -05:00
Rich Harris
43c1890235 handle case where webpack asset is an array instead of a string 2018-02-20 11:11:55 -05:00
Rich Harris
605929053c ensure old server is killed before listening for port on new server 2018-02-20 11:11:02 -05:00
Rich Harris
2752c73ebb -> v0.7.2 2018-02-18 17:24:12 -05:00
Rich Harris
2547db39ac -> v0.7.1 2018-02-18 17:09:55 -05:00
Rich Harris
1285739cc5 -> v0.7.1 2018-02-18 17:08:35 -05:00
6 changed files with 69 additions and 32 deletions

View File

@@ -1,5 +1,19 @@
# 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
* Add missing `tslib` dependency
## 0.7.0
* Restructure app layout (see [migration guide](https://sapper.svelte.technology/guide#0-6-to-0-7)) ([#126](https://github.com/sveltejs/sapper/pull/126))

View File

@@ -1,7 +1,5 @@
let source;
console.log('!!!! hmr client');
function check() {
if (module.hot.status() === 'idle') {
module.hot.check(true).then(modules => {

View File

@@ -1,6 +1,6 @@
{
"name": "sapper",
"version": "0.7.0",
"version": "0.7.3",
"description": "Military-grade apps, engineered by Svelte",
"main": "middleware.js",
"bin": {
@@ -12,6 +12,7 @@
"middleware.js",
"runtime",
"runtime.js",
"hmr-client.js",
"webpack"
],
"directories": {
@@ -24,6 +25,7 @@
"code-frame": "^5.0.0",
"escape-html": "^1.0.3",
"express": "^4.16.2",
"get-port": "^3.2.0",
"glob": "^7.1.2",
"locate-character": "^2.0.5",
"mime": "^2.2.0",
@@ -35,6 +37,7 @@
"rimraf": "^2.6.2",
"sander": "^0.6.0",
"serialize-javascript": "^1.4.0",
"tslib": "^1.8.1",
"url-parse": "^1.2.0",
"wait-port": "^0.2.2",
"walk-sync": "^0.3.2",
@@ -50,7 +53,6 @@
"electron": "^1.8.2",
"eslint": "^4.13.1",
"eslint-plugin-import": "^2.8.0",
"get-port": "^3.2.0",
"mocha": "^4.0.1",
"nightmare": "^2.10.0",
"npm-run-all": "^4.1.2",
@@ -63,7 +65,6 @@
"svelte": "^1.49.1",
"svelte-loader": "^2.3.2",
"ts-node": "^4.1.0",
"tslib": "^1.8.1",
"typescript": "^2.6.2"
},
"scripts": {

View File

@@ -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, ' '));
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`, [], {
cwd: process.cwd(),
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 }),
client_files,
src
});
watch_serviceworker();
}
});
if (compilers.serviceworker) {
compilers.serviceworker.plugin('invalid', (filename: string) => {
times.serviceworker_start = Date.now();
});
let watch_serviceworker = compilers.serviceworker
? function() {
watch_serviceworker = noop;
compilers.serviceworker.watch({}, (err: Error, stats: any) => {
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
compilers.serviceworker.plugin('invalid', (filename: string) => {
times.serviceworker_start = Date.now();
});
const serviceworker_info = stats.toJson();
fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' '));
}
});
}
}
compilers.serviceworker.watch({}, (err: Error, stats: any) => {
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() {}

View File

@@ -41,7 +41,7 @@ function generate_client(routes: Route[], src: string, dev: boolean, dev_port?:
if (dev) {
const hmr_client = posixify(
path.resolve(__dirname, 'src/hmr-client.js')
path.resolve(__dirname, 'hmr-client.js')
);
code += `

View File

@@ -122,7 +122,12 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
// preload main.js and current route
// 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 };
@@ -159,7 +164,11 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
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}`;
const page = template.render({