mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 05:25:08 +00:00
add SAPPER_BASE and SAPPER_APP environment variables
This commit is contained in:
@@ -4,10 +4,10 @@ import * as clorox from 'clorox';
|
|||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
|
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
|
||||||
import { dest } from '../config';
|
import { locations } from '../config';
|
||||||
|
|
||||||
export async function build() {
|
export async function build() {
|
||||||
const output = dest();
|
const output = locations.dest();
|
||||||
|
|
||||||
mkdirp.sync(output);
|
mkdirp.sync(output);
|
||||||
rimraf.sync(path.join(output, '**/*'));
|
rimraf.sync(path.join(output, '**/*'));
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import rimraf from 'rimraf';
|
|||||||
import format_messages from 'webpack-format-messages';
|
import format_messages from 'webpack-format-messages';
|
||||||
import prettyMs from 'pretty-ms';
|
import prettyMs from 'pretty-ms';
|
||||||
import * as ports from 'port-authority';
|
import * as ports from 'port-authority';
|
||||||
import { dest } from '../config';
|
import { locations } from '../config';
|
||||||
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core';
|
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core';
|
||||||
|
|
||||||
type Deferred = {
|
type Deferred = {
|
||||||
@@ -84,7 +84,7 @@ export async function dev(opts: { port: number }) {
|
|||||||
port = await ports.find(3000);
|
port = await ports.find(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = dest();
|
const dir = locations.dest();
|
||||||
rimraf.sync(dir);
|
rimraf.sync(dir);
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import cheerio from 'cheerio';
|
|||||||
import URL from 'url-parse';
|
import URL from 'url-parse';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import * as ports from 'port-authority';
|
import * as ports from 'port-authority';
|
||||||
import { dest } from '../config';
|
import { locations } from '../config';
|
||||||
|
|
||||||
export async function exporter(export_dir: string) {
|
export async function exporter(export_dir: string) {
|
||||||
const build_dir = dest();
|
const build_dir = locations.dest();
|
||||||
|
|
||||||
// Prep output directory
|
// Prep output directory
|
||||||
sander.rimrafSync(export_dir);
|
sander.rimrafSync(export_dir);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export const dev = () => process.env.NODE_ENV !== 'production';
|
export const dev = () => process.env.NODE_ENV !== 'production';
|
||||||
export const src = () => path.resolve(process.env.SAPPER_ROUTES || 'routes');
|
|
||||||
export const dest = () => path.resolve(process.env.SAPPER_DEST || '.sapper');
|
export const locations = {
|
||||||
|
base: () => path.resolve(process.env.SAPPER_BASE || ''),
|
||||||
|
app: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_APP || 'app'),
|
||||||
|
routes: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_ROUTES || 'routes'),
|
||||||
|
dest: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_DEST || '.sapper')
|
||||||
|
};
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import glob from 'glob';
|
import glob from 'glob';
|
||||||
import { src } from '../config';
|
import { locations } from '../config';
|
||||||
import { Route } from '../interfaces';
|
import { Route } from '../interfaces';
|
||||||
|
|
||||||
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: src(), nodir: true }) }) {
|
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), nodir: true }) }) {
|
||||||
const routes: Route[] = files
|
const routes: Route[] = files
|
||||||
.map((file: string) => {
|
.map((file: string) => {
|
||||||
if (/(^|\/|\\)_/.test(file)) return;
|
if (/(^|\/|\\)_/.test(file)) return;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import devalue from 'devalue';
|
|||||||
import { lookup } from './middleware/mime';
|
import { lookup } from './middleware/mime';
|
||||||
import { minify_html } from './middleware/minify_html';
|
import { minify_html } from './middleware/minify_html';
|
||||||
import { create_routes, create_compilers } from './core';
|
import { create_routes, create_compilers } from './core';
|
||||||
import { dest, dev } from './config';
|
import { locations, dev } from './config';
|
||||||
import { Route, Template } from './interfaces';
|
import { Route, Template } from './interfaces';
|
||||||
import sourceMapSupport from 'source-map-support';
|
import sourceMapSupport from 'source-map-support';
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ interface Req extends ClientRequest {
|
|||||||
export default function middleware({ routes }: {
|
export default function middleware({ routes }: {
|
||||||
routes: RouteObject[]
|
routes: RouteObject[]
|
||||||
}) {
|
}) {
|
||||||
const output = dest();
|
const output = locations.dest();
|
||||||
|
|
||||||
const client_info = JSON.parse(fs.readFileSync(path.join(output, 'client_info.json'), 'utf-8'));
|
const client_info = JSON.parse(fs.readFileSync(path.join(output, 'client_info.json'), 'utf-8'));
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ function serve({ prefix, pathname, cache_control }: {
|
|||||||
? (req: Req) => req.pathname === pathname
|
? (req: Req) => req.pathname === pathname
|
||||||
: (req: Req) => req.pathname.startsWith(prefix);
|
: (req: Req) => req.pathname.startsWith(prefix);
|
||||||
|
|
||||||
const output = dest();
|
const output = locations.dest();
|
||||||
|
|
||||||
const cache: Map<string, Buffer> = new Map();
|
const cache: Map<string, Buffer> = new Map();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { dest, dev } from './config';
|
import { locations, dev } from './config';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
dev: dev(),
|
dev: dev(),
|
||||||
@@ -12,7 +12,7 @@ export default {
|
|||||||
|
|
||||||
output: () => {
|
output: () => {
|
||||||
return {
|
return {
|
||||||
path: `${dest()}/client`,
|
path: `${locations.dest()}/client`,
|
||||||
filename: '[hash]/[name].js',
|
filename: '[hash]/[name].js',
|
||||||
chunkFilename: '[hash]/[name].[id].js',
|
chunkFilename: '[hash]/[name].[id].js',
|
||||||
publicPath: '/client/'
|
publicPath: '/client/'
|
||||||
@@ -29,7 +29,7 @@ export default {
|
|||||||
|
|
||||||
output: () => {
|
output: () => {
|
||||||
return {
|
return {
|
||||||
path: dest(),
|
path: locations.dest(),
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
chunkFilename: '[hash]/[name].[id].js',
|
chunkFilename: '[hash]/[name].[id].js',
|
||||||
libraryTarget: 'commonjs2'
|
libraryTarget: 'commonjs2'
|
||||||
@@ -46,7 +46,7 @@ export default {
|
|||||||
|
|
||||||
output: () => {
|
output: () => {
|
||||||
return {
|
return {
|
||||||
path: dest(),
|
path: locations.dest(),
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
chunkFilename: '[name].[id].[hash].js'
|
chunkFilename: '[name].[id].[hash].js'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user