mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
preserve webpack stats, write client assets elsewhere
This commit is contained in:
@@ -61,9 +61,9 @@ async function execute(emitter: EventEmitter, {
|
|||||||
webpack_stats: client_stats
|
webpack_stats: client_stats
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(path.join(dest, 'client_info.json'), JSON.stringify({
|
const client_info = client_stats.toJson();
|
||||||
assets: client_stats.toJson().assetsByChunkName
|
fs.writeFileSync(path.join(dest, 'client_info.json'), JSON.stringify(client_info));
|
||||||
}));
|
fs.writeFileSync(path.join(dest, 'client_assets.json'), JSON.stringify(client_info.assetsByChunkName));
|
||||||
|
|
||||||
const server_stats = await compile(server);
|
const server_stats = await compile(server);
|
||||||
emitter.emit('build', <events.BuildEvent>{
|
emitter.emit('build', <events.BuildEvent>{
|
||||||
|
|||||||
@@ -189,9 +189,8 @@ class Watcher extends EventEmitter {
|
|||||||
},
|
},
|
||||||
|
|
||||||
result: info => {
|
result: info => {
|
||||||
fs.writeFileSync(path.join(dest, 'client_info.json'), JSON.stringify({
|
fs.writeFileSync(path.join(dest, 'client_info.json'), JSON.stringify(info));
|
||||||
assets: info.assetsByChunkName
|
fs.writeFileSync(path.join(dest, 'client_info.json'), JSON.stringify(info.assetsByChunkName, null, ' '));
|
||||||
}, null, ' '));
|
|
||||||
this.deferreds.client.fulfil();
|
this.deferreds.client.fulfil();
|
||||||
|
|
||||||
const client_files = info.assets.map((chunk: { name: string }) => `client/${chunk.name}`);
|
const client_files = info.assets.map((chunk: { name: string }) => `client/${chunk.name}`);
|
||||||
@@ -291,20 +290,14 @@ class Watcher extends EventEmitter {
|
|||||||
const duplicate = this.current_build.unique_errors.has(message);
|
const duplicate = this.current_build.unique_errors.has(message);
|
||||||
this.current_build.unique_errors.add(message);
|
this.current_build.unique_errors.add(message);
|
||||||
|
|
||||||
return {
|
return mungeWebpackError(message, duplicate);
|
||||||
message,
|
|
||||||
duplicate
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
warnings: messages.warnings.map((message: string) => {
|
warnings: messages.warnings.map((message: string) => {
|
||||||
const duplicate = this.current_build.unique_warnings.has(message);
|
const duplicate = this.current_build.unique_warnings.has(message);
|
||||||
this.current_build.unique_warnings.add(message);
|
this.current_build.unique_warnings.add(message);
|
||||||
|
|
||||||
return {
|
return mungeWebpackError(message, duplicate);
|
||||||
message,
|
|
||||||
duplicate
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -314,6 +307,37 @@ class Watcher extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const locPattern = /\((\d+):(\d+)\)$/;
|
||||||
|
|
||||||
|
function mungeWebpackError(message: string, duplicate: boolean) {
|
||||||
|
// TODO this is all a bit rube goldberg...
|
||||||
|
const lines = message.split('\n');
|
||||||
|
|
||||||
|
const file = lines.shift()
|
||||||
|
.replace('[7m', '') // careful — there is a special character at the beginning of this string
|
||||||
|
.replace('[27m', '')
|
||||||
|
.replace('./', '');
|
||||||
|
|
||||||
|
let line = null;
|
||||||
|
let column = null;
|
||||||
|
|
||||||
|
const match = locPattern.exec(lines[0]);
|
||||||
|
if (match) {
|
||||||
|
lines[0] = lines[0].replace(locPattern, '');
|
||||||
|
line = +match[1];
|
||||||
|
column = +match[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
file,
|
||||||
|
line,
|
||||||
|
column,
|
||||||
|
message: lines.join('\n'),
|
||||||
|
originalMessage: message,
|
||||||
|
duplicate
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class Deferred {
|
class Deferred {
|
||||||
promise: Promise<any>;
|
promise: Promise<any>;
|
||||||
fulfil: (value?: any) => void;
|
fulfil: (value?: any) => void;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
import create_routes from './create_routes';
|
|
||||||
import { posixify, write_if_changed } from './utils';
|
import { posixify, write_if_changed } from './utils';
|
||||||
import { dev, locations } from '../config';
|
import { dev, locations } from '../config';
|
||||||
import { Route } from '../interfaces';
|
import { Route } from '../interfaces';
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import rimraf from 'rimraf';
|
|||||||
import devalue from 'devalue';
|
import devalue from 'devalue';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { lookup } from './middleware/mime';
|
import { lookup } from './middleware/mime';
|
||||||
import { create_routes, create_compilers } from './core';
|
|
||||||
import { locations, dev } from './config';
|
import { locations, dev } from './config';
|
||||||
import { Route, Template } from './interfaces';
|
import { Route, Template } from './interfaces';
|
||||||
import sourceMapSupport from 'source-map-support';
|
import sourceMapSupport from 'source-map-support';
|
||||||
@@ -60,7 +59,7 @@ export default function middleware({ App, routes, store }: {
|
|||||||
|
|
||||||
const output = locations.dest();
|
const output = locations.dest();
|
||||||
|
|
||||||
const client_info = JSON.parse(fs.readFileSync(path.join(output, 'client_info.json'), 'utf-8'));
|
const client_assets = JSON.parse(fs.readFileSync(path.join(output, 'client_assets.json'), 'utf-8'));
|
||||||
|
|
||||||
const middleware = compose_handlers([
|
const middleware = compose_handlers([
|
||||||
(req: Req, res: ServerResponse, next: () => void) => {
|
(req: Req, res: ServerResponse, next: () => void) => {
|
||||||
@@ -97,7 +96,7 @@ export default function middleware({ App, routes, store }: {
|
|||||||
cache_control: 'max-age=31536000'
|
cache_control: 'max-age=31536000'
|
||||||
}),
|
}),
|
||||||
|
|
||||||
get_route_handler(client_info.assets, App, routes, store)
|
get_route_handler(client_assets, App, routes, store)
|
||||||
].filter(Boolean));
|
].filter(Boolean));
|
||||||
|
|
||||||
return middleware;
|
return middleware;
|
||||||
|
|||||||
Reference in New Issue
Block a user