tidy up a bit

This commit is contained in:
Rich Harris
2018-01-21 15:04:22 -05:00
parent dd8deb2d8a
commit 03ce2ea998
13 changed files with 19 additions and 519 deletions

View File

@@ -1,20 +1,11 @@
import * as path from 'path';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
export const dev = process.env.NODE_ENV !== 'production';
export const templates = path.resolve(process.env.SAPPER_TEMPLATES || 'templates');
export const src = path.resolve(process.env.SAPPER_ROUTES || 'routes');
export const dest = path.resolve(process.env.SAPPER_DEST || '.sapper');
if (dev) {
mkdirp.sync(dest);
rimraf.sync(path.join(dest, '**/*'));
}
export const entry = {
client: path.resolve(templates, '.main.rendered.js'),
server: path.resolve(dest, 'server-entry.js')

View File

@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import glob from 'glob';
import * as templates from './templates.js';
import { create_templates, render } from './templates.js';
import * as route_manager from './route_manager.js';
function ensure_array(thing) {
@@ -9,7 +9,7 @@ function ensure_array(thing) {
}
export default function generate_asset_cache({ src, dest, dev, client_info, server_info }) {
templates.create_templates(); // TODO refactor this...
create_templates(); // TODO refactor this...
const main_file = `/client/${ensure_array(client_info.assetsByChunkName.main)[0]}`;
@@ -71,7 +71,7 @@ function generate_service_worker({ chunk_files, src }) {
}
function generate_index(main_file) {
return templates.render(200, {
return render(200, {
styles: '',
head: '',
html: '<noscript>Please enable JavaScript!</noscript>',

View File

@@ -1,12 +1,9 @@
import * as path from 'path';
import relative from 'require-relative';
const webpack = relative('webpack', process.cwd());
export let client;
export let server;
export function get_compilers() {
const webpack = relative('webpack', process.cwd());
return {
client: webpack(
require(path.resolve('webpack.client.config.js'))
@@ -16,12 +13,4 @@ export function get_compilers() {
require(path.resolve('webpack.server.config.js'))
)
};
}
// export const client = webpack(
// require(path.resolve('webpack.client.config.js'))
// );
// export const server = webpack(
// require(path.resolve('webpack.server.config.js'))
// );
}

View File

@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as route_manager from '../route_manager.js';
import * as templates from '../templates.js';
import { create_templates } from '../templates.js';
function posixify(file) {
return file.replace(/[/\\]/g, '/');
@@ -90,7 +90,7 @@ export function start_watching({ src }) {
});
watch('templates/**.html', () => {
templates.create_templates();
create_templates();
// TODO reload current page?
});
}

View File

@@ -1,5 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import serialize from 'serialize-javascript';
import escape_html from 'escape-html';
import { route_manager, templates, create_app, compilers, generate_asset_cache } from 'sapper/core.js';
@@ -7,6 +9,9 @@ import create_watcher from './create_watcher.js';
import { dest, dev, entry, src } from '../config.js';
function connect_dev() {
mkdirp.sync(dest);
rimraf.sync(path.join(dest, '**/*'));
create_app({ dev, entry, src });
const watcher = create_watcher();