本文整理汇总了TypeScript中tiny-lr类的典型用法代码示例。如果您正苦于以下问题:TypeScript tiny-lr类的具体用法?TypeScript tiny-lr怎么用?TypeScript tiny-lr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了tiny-lr类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: serveSPA
import * as connectLivereload from 'connect-livereload';
import * as express from 'express';
import * as tinylrFn from 'tiny-lr';
import * as openResource from 'open';
import * as serveStatic from 'serve-static';
import {resolve} from 'path';
import {APP_BASE, APP_DEST, LIVE_RELOAD_PORT, PORT} from '../config';
let tinylr = tinylrFn();
export function serveSPA() {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT }),
express.static(process.cwd())
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE + APP_DEST)
);
}
export function notifyLiveReload(e) {
let fileName = e.path;
tinylr.changed({
body: { files: [fileName] }
});
示例2: notifyLiveReload
import * as tslintStylish from 'gulp-tslint-stylish';
import * as shell from 'gulp-shell';
import * as nodemon from 'gulp-nodemon';
import {Server} from 'karma';
import * as ts from 'gulp-typescript';
import * as sourcemaps from 'gulp-sourcemaps';
import * as tinylrFn from 'tiny-lr';
import {PATH, LIVE_RELOAD_PORT, APP_BASE, APP_VERSION, DEPS_SRC} from './tools/config';
export const templateLocals = {
APP_VERSION,
APP_BASE
};
const tinylr = tinylrFn();
export function notifyLiveReload(changedFiles: string[]) {
tinylr.changed({
body: { files: changedFiles }
});
}
const tsProject = ts.createProject('tsconfig.json');
function compileTs(src: string | string[], dest: string, inlineTpl?: boolean): NodeJS.ReadWriteStream {
let result = gulp.src(src)
.pipe(plumber())
.pipe(sourcemaps.init());
示例3: notifyLiveReload
import * as gulp from 'gulp';
import {join} from 'path';
import * as inject from 'gulp-inject';
import * as template from 'gulp-template';
import * as tinylrFn from 'tiny-lr';
import {PATH, APP_BASE, APP_VERSION, LIVE_RELOAD_PORT} from './config';
export const tinylr = tinylrFn();
export function notifyLiveReload(changedFiles: string[]) {
tinylr.changed({
body: { files: changedFiles }
});
}
export function buildInjectable(paths: string[], newBaseDir?: string, newExt?: string): NodeJS.ReadWriteStream {
const rws = gulp.src(
paths
.filter(path => !/(\.map)$/.test(path), { read: false })
);
return rws;
}
export function transformPath(filepath: string, newBaseDir: string) {
const namePos = filepath.lastIndexOf('/') + 1;
const filename = filepath.substring(namePos);
filepath = newBaseDir === '' ? filename : newBaseDir + '/' + filename;
return filepath;
}
示例4: tinylr
}).once('start', () => {
const tinylrObj = tinylr();
tinylrObj.listen(LIVE_RELOAD_PORT);
const intervalId = setInterval(() => {
const existsDist = fse.existsSync(PATHS.dest.dist.appBundle);
if (existsDist) {
clearInterval(intervalId);
setTimeout(() => {
openResource(`http://localhost:${PORT}`);
done();
}, 3000);
}
}, 500);
})
示例5: createLiveReloadServer
export function createLiveReloadServer(config: ServeConfig) {
const liveReloadServer = tinylr();
liveReloadServer.listen(config.liveReloadPort, config.host);
function fileChange(changedFiles: ChangedFile[]) {
// only do a live reload if there are no diagnostics
// the notification server takes care of showing diagnostics
if (!hasDiagnostics(config.buildDir)) {
liveReloadServer.changed({
body: {
files: changedFiles.map(changedFile => '/' + path.relative(config.wwwDir, changedFile.filePath))
}
});
}
}
events.on(events.EventType.FileChange, fileChange);
events.on(events.EventType.ReloadApp, () => {
fileChange([{ event: 'change', ext: '.html', filePath: 'index.html'}]);
});
}