This commit is contained in:
Rich Harris
2018-08-29 10:55:52 -04:00
parent 7e698f1613
commit f8d742bdd0
2 changed files with 32 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ export class CompileResult {
} }
class RollupResult extends CompileResult { class RollupResult extends CompileResult {
constructor(duration: number, stats: any) { constructor(duration: number, { input, chunks }: { input: string, chunks: any[] }) {
super(); super();
this.duration = duration; this.duration = duration;
@@ -30,14 +30,17 @@ class RollupResult extends CompileResult {
this.errors = []; this.errors = [];
this.warnings = []; this.warnings = [];
// TODO this.assets = chunks.map(chunk => chunk.fileName);
this.assets = [];
this.assetsByChunkName = { // TODO populate this properly. We don't have named chunks, as in
// TODO need to hash these filenames and // webpack, but we can have a route -> [chunk] map or something
// expose the info in the Rollup output this.assetsByChunkName = {};
main: `client.js`
}; chunks.forEach(chunk => {
if (input in chunk.modules) {
this.assetsByChunkName.main = chunk.fileName;
}
});
} }
print() { print() {
@@ -77,9 +80,13 @@ export class RollupCompiler {
_: Promise<any>; _: Promise<any>;
_oninvalid: (filename: string) => void; _oninvalid: (filename: string) => void;
_start: number; _start: number;
input: string;
chunks: any[]; // TODO types
constructor(config: any) { constructor(config: any) {
this._ = this.get_config(path.resolve(config)); this._ = this.get_config(path.resolve(config));
this.input = null;
this.chunks = [];
} }
async get_config(input: string) { async get_config(input: string) {
@@ -107,8 +114,13 @@ export class RollupCompiler {
(mod.plugins || (mod.plugins = [])).push({ (mod.plugins || (mod.plugins = [])).push({
name: 'sapper-internal', name: 'sapper-internal',
watchChange: (file: string) => { options: (opts: any) => {
this._oninvalid(file); this.input = opts.input;
},
renderChunk: (code: string, chunk: any) => {
if (chunk.isEntry) {
this.chunks.push(chunk);
}
} }
}); });
@@ -135,6 +147,10 @@ export class RollupCompiler {
const watcher = r.watch(config); const watcher = r.watch(config);
watcher.on('change', (id: string) => {
this._oninvalid(id);
});
watcher.on('event', (event: any) => { watcher.on('event', (event: any) => {
switch (event.code) { switch (event.code) {
case 'FATAL': case 'FATAL':
@@ -157,7 +173,10 @@ export class RollupCompiler {
break; break;
case 'BUNDLE_END': case 'BUNDLE_END':
cb(null, new RollupResult(Date.now() - this._start, event.result)); cb(null, new RollupResult(Date.now() - this._start, {
input: this.input,
chunks: this.chunks
}));
break; break;
default: default:

View File

@@ -11,6 +11,8 @@ export default {
output: () => { output: () => {
return { return {
dir: `${locations.dest()}/client`, dir: `${locations.dest()}/client`,
entryFileNames: '[name].[hash].js',
chunkFileNames: '[name].[hash].js',
format: 'esm' format: 'esm'
}; };
} }