mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 05:25:08 +00:00
hashing
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -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'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user