Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

[WIP] implement --basepath flag (#180) #199

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ test/app/.sapper
test/app/app/manifest
test/app/export
test/app/build
*.js
*.js.map
*.ts.js
*.ts.js.map
sapper
runtime.js
dist
!rollup.config.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"compression": "^1.7.1",
"eslint": "^4.13.1",
"eslint-plugin-import": "^2.8.0",
"express": "^4.16.3",
"get-port": "^3.2.0",
"mocha": "^5.0.4",
"nightmare": "^3.0.0",
Expand Down
271 changes: 0 additions & 271 deletions runtime.js

This file was deleted.

13 changes: 10 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ prog.command('dev')
.describe('Start a development server')
.option('-p, --port', 'Specify a port')
.option('-o, --open', 'Open a browser window')
.action(async (opts: { port: number, open: boolean }) => {
.option('--basepath', 'Specify a base path')
.action(async (opts: { port: number, open: boolean, basepath: string }) => {
if (opts.basepath) process.env.SAPPER_BASEPATH = opts.basepath;

const { dev } = await import('./cli/dev');
dev(opts);
});

prog.command('build [dest]')
.describe('Create a production-ready version of your app')
.action(async (dest = 'build') => {
.option('--basepath', 'Specify a base path')
.action(async (dest = 'build', opts: { basepath: string }) => {
console.log(`> Building...`);

process.env.NODE_ENV = 'production';
process.env.SAPPER_DEST = dest;
if (opts.basepath) process.env.SAPPER_BASEPATH = opts.basepath;

const start = Date.now();

Expand All @@ -49,11 +54,13 @@ prog.command('start [dir]')

prog.command('export [dest]')
.describe('Export your app as static files (if possible)')
.action(async (dest = 'export') => {
.option('--basepath', 'Specify a base path')
.action(async (dest = 'export', opts: { basepath: string }) => {
console.log(`> Building...`);

process.env.NODE_ENV = 'production';
process.env.SAPPER_DEST = '.sapper/.export';
if (opts.basepath) process.env.SAPPER_BASEPATH = opts.basepath;

const start = Date.now();

Expand Down
9 changes: 7 additions & 2 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import { minify_html } from './utils/minify_html';
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
import { locations } from '../config';
import { basepath, locations } from '../config';

export async function build() {
const output = locations.dest();
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function build() {
if (serviceworker) {
create_serviceworker_manifest({
routes,
client_files: client_stats.toJson().assets.map((chunk: { name: string }) => `/client/${chunk.name}`)
client_files: client_stats.toJson().assets.map((chunk: { name: string }) => `client/${chunk.name}`)
});

serviceworker_stats = await compile(serviceworker);
Expand All @@ -46,6 +46,11 @@ export async function build() {
// TODO compile this to a function? could be quicker than str.replace(...).replace(...).replace(...)
const template = fs.readFileSync(`${locations.app()}/template.html`, 'utf-8');
fs.writeFileSync(`${output}/template.html`, minify_html(template));

// write out a manifest
fs.writeFileSync(`${output}/manifest.json`, JSON.stringify({
basepath: basepath()
}, null, ' '));
}

function compile(compiler: any) {
Expand Down
8 changes: 6 additions & 2 deletions src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rimraf from 'rimraf';
import format_messages from 'webpack-format-messages';
import prettyMs from 'pretty-ms';
import * as ports from 'port-authority';
import { locations } from '../config';
import { basepath, locations } from '../config';
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core';

type Deferred = {
Expand Down Expand Up @@ -90,6 +90,10 @@ export async function dev(opts: { port: number, open: boolean }) {

const dev_port = await ports.find(10000);

fs.writeFileSync(`${dir}/manifest.json`, JSON.stringify({
basepath: basepath()
}, null, ' '));

const routes = create_routes();
create_main_manifests({ routes, dev_port });

Expand Down Expand Up @@ -259,7 +263,7 @@ export async function dev(opts: { port: number, open: boolean }) {
fs.writeFileSync(path.join(dir, 'client_info.json'), JSON.stringify(info, null, ' '));
deferreds.client.fulfil();

const client_files = info.assets.map((chunk: { name: string }) => `/client/${chunk.name}`);
const client_files = info.assets.map((chunk: { name: string }) => `client/${chunk.name}`);

deferreds.server.promise.then(() => {
hot_update_server.send({
Expand Down
Loading