mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 04:44:35 +00:00
basic sapper dev task, with HMR
This commit is contained in:
@@ -18,7 +18,8 @@ export default function create_app({ routes, src, dev }: {
|
||||
|
||||
function generate_client(routes: Route[], src: string, dev: boolean) {
|
||||
let code = `
|
||||
// This file is generated by Sapper — do not edit it!\nexport const routes = [
|
||||
// This file is generated by Sapper — do not edit it!
|
||||
export const routes = [
|
||||
${routes
|
||||
.filter(route => route.type === 'page')
|
||||
.map(route => {
|
||||
@@ -34,10 +35,18 @@ function generate_client(routes: Route[], src: string, dev: boolean) {
|
||||
|
||||
if (dev) {
|
||||
const hmr_client = posixify(
|
||||
require.resolve(`webpack-hot-middleware/client`)
|
||||
path.resolve(__dirname, 'src/hmr-client.js')
|
||||
);
|
||||
|
||||
code += `\n\nimport('${hmr_client}?path=/__webpack_hmr&timeout=20000'); if (module.hot) module.hot.accept();`;
|
||||
const PORT = 23456; // TODO robustify this — needs to be controlled by the dev task
|
||||
|
||||
code += `
|
||||
|
||||
if (module.hot) {
|
||||
import('${hmr_client}').then(client => {
|
||||
client.connect(${PORT});
|
||||
});
|
||||
}`.replace(/^\t{3}/gm, '');
|
||||
}
|
||||
|
||||
return code;
|
||||
|
||||
Reference in New Issue
Block a user