mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 03:25:24 +00:00
lazy-load stuff
This commit is contained in:
@@ -6,7 +6,7 @@ import rimraf from 'rimraf';
|
||||
import { create_compilers, create_app, create_routes, create_serviceworker } from '../core'
|
||||
import { src, dest, dev } from '../config';
|
||||
|
||||
export default async function build() {
|
||||
export async function build() {
|
||||
const output = dest();
|
||||
|
||||
mkdirp.sync(output);
|
||||
|
||||
@@ -70,9 +70,20 @@ function create_hot_update_server(port: number, interval = 10000) {
|
||||
return { send };
|
||||
}
|
||||
|
||||
export default async function dev(port: number) {
|
||||
export async function dev(opts: { port: number }) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
let port = opts.port || +process.env.PORT;
|
||||
|
||||
if (port) {
|
||||
if (!await ports.check(port)) {
|
||||
console.log(clorox.bold.red(`> Port ${port} is unavailable`));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
port = await ports.find(3000);
|
||||
}
|
||||
|
||||
const dir = dest();
|
||||
rimraf.sync(dir);
|
||||
mkdirp.sync(dir);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { dest } from '../config';
|
||||
|
||||
const app = polka();
|
||||
|
||||
export default async function exporter(export_dir: string) {
|
||||
export async function exporter(export_dir: string) {
|
||||
const build_dir = dest();
|
||||
|
||||
// Prep output directory
|
||||
|
||||
35
src/cli/start.ts
Normal file
35
src/cli/start.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as child_process from 'child_process';
|
||||
import * as clorox from 'clorox';
|
||||
import * as ports from 'port-authority';
|
||||
|
||||
export async function start(dir: string, opts: { port: number }) {
|
||||
let port = opts.port || +process.env.PORT;
|
||||
|
||||
const resolved = path.resolve(dir);
|
||||
const server = path.resolve(dir, 'server.js');
|
||||
|
||||
if (!fs.existsSync(server)) {
|
||||
console.log(clorox.bold.red(`> ${dir}/server.js does not exist — type ${clorox.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`));
|
||||
return;
|
||||
}
|
||||
|
||||
if (port) {
|
||||
if (!await ports.check(port)) {
|
||||
console.log(clorox.bold.red(`> Port ${port} is unavailable`));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
port = await ports.find(3000);
|
||||
}
|
||||
|
||||
child_process.fork(server, [], {
|
||||
cwd: process.cwd(),
|
||||
env: Object.assign({
|
||||
NODE_ENV: 'production',
|
||||
PORT: port,
|
||||
SAPPER_DEST: dir
|
||||
}, process.env)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user