本文整理匯總了TypeScript中connect-livereload.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect-livereload.default方法的具體用法?TypeScript connect-livereload.default怎麽用?TypeScript connect-livereload.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類connect-livereload
的用法示例。
在下文中一共展示了connect-livereload.default方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: connect
/// <reference path="./connect-livereload.d.ts" />
import * as connect from "connect";
import * as livereload from "connect-livereload";
const app = connect();
// With no options
app.use(livereload());
// With string options
app.use(livereload({
port: 35729,
ignore: [".js", ".svg"]
}));
// With RegExp options
app.use(livereload({
port: 35729,
ignore: [/\.js(\?.*)?$/, /\.css(\?.*)?$/]
}));
// With default options
app.use(livereload({
ignore: [
/\.js(\?.*)?$/, /\.css(\?.*)?$/, /\.svg(\?.*)?$/, /\.ico(\?.*)?$/, /\.woff(\?.*)?$/,
/\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/, /\.gif(\?.*)?$/, /\.pdf(\?.*)?$/
],
// include all urls by default
include: [/.*/],
示例2: serveSPA
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)
);
}
示例3: serveSPA
export function serveSPA(env) {
let app = express();
app.use(
APP_BASE,
connectLivereload({port: LIVE_RELOAD_PORT}),
serveStatic(resolve(process.cwd(), PATH.dest[env].all))
);
app.all(APP_BASE + '*', (req, res) =>
res.sendFile(resolve(process.cwd(), PATH.dest[env].all, 'index.html'))
);
app.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE)
);
}
示例4: serveSPA
export function serveSPA() {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT }),
serveStatic(resolve(process.cwd(), APP_DEST))
);
server.all(APP_BASE + '*', (req, res) =>
res.sendFile(resolve(process.cwd(), APP_DEST, 'index.html'))
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE)
);
}
示例5: resolve
import * as connectLivereload from 'connect-livereload';
import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as openResource from 'open';
import {resolve} from 'path';
import {APP_BASE, LIVE_RELOAD_PORT, PATH, PORT} from '../tools/config';
const INDEX_DEST_PATH = resolve(PATH.cwd, PATH.dest.app.base, 'index.html');
const server = express();
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT })
);
server.use(express.static(PATH.dest.app.base));
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.get('/api/**', (req, res, next) => {
// TODO: remove this. It just mimics a delay in the backend.
const delay = Math.floor((Math.random() * 300) + 1);
setTimeout(() => next(), delay);
});
server.get(APP_BASE + '*', (req, res) =>
res.sendFile(INDEX_DEST_PATH)
);
示例6: connectLivereload
}
};
let changed = files => {
if (!(files instanceof Array)) {
files = [files];
}
if (ENABLE_HOT_LOADING) {
ng2HotLoader.onChange(files);
} else {
tinylr.changed({
body: { files }
});
}
};
let tinylrMiddleware = connectLivereload({ port: LIVE_RELOAD_PORT });
let middleware = [
APP_BASE,
(req, res, next) => {
if (ENABLE_HOT_LOADING) {
next();
} else {
tinylrMiddleware(req, res, next);
}
},
express.static(process.cwd())
];
export { listen, changed, middleware };
示例7: express
let serveSPA = () => {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(compression());
server.use(bodyParser.json());
server.get('/imageids', (req, res) => {
res.json({imageIds: randomImages.getIds()});
});
server.get('/lastmodified', (req, res) => {
res.json(lastModified);
});
server.get('/errorconfig', (req, res) => {
res.json(errorConfig);
});
/**
* Validates user submission and sends the message received via the contact from
*
* @param {Object} submission
* @param {string} submission.name
* @param {string} submission.email
* @param {string} submission.text
* @param {string} submission.heuning
*/
server.post('/send', (req, res) => {
let submission:Submission = req.body,
errors:Array<string> = mailHelper.validate(submission);
if (errors.length > 0) {
res.status(400).send({errors: errors});
} else {
let message:Message = mailHelper.buildMessage(submission),
messageCopy:Message = mailHelper.buildMessageCopy(submission);
nodeMailer.send(message, (success:boolean) => {
if (success) {
nodeMailer.send(messageCopy, (success:boolean) => {
if (success) {
res.status(200).json('Sent successfully');
} else {
res.sendStatus(500);
}
});
} else {
res.sendStatus(500);
}
});
}
});
server.use(
APP_BASE,
connectLivereload({port: LIVE_RELOAD_PORT}),
express.static(process.cwd())
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE + APP_DEST)
);
};