mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 21:45:12 +00:00
emit legacy build
This commit is contained in:
@@ -5,9 +5,7 @@ import rimraf from 'rimraf';
|
|||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import minify_html from './utils/minify_html';
|
import minify_html from './utils/minify_html';
|
||||||
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 { Compilers, Compiler } from '../core/create_compilers';
|
|
||||||
import * as events from './interfaces';
|
import * as events from './interfaces';
|
||||||
import validate_bundler from '../cli/utils/validate_bundler';
|
|
||||||
import { copy_shimport } from './utils/copy_shimport';
|
import { copy_shimport } from './utils/copy_shimport';
|
||||||
|
|
||||||
export function build(opts: {}) {
|
export function build(opts: {}) {
|
||||||
@@ -30,6 +28,7 @@ export function build(opts: {}) {
|
|||||||
async function execute(emitter: EventEmitter, {
|
async function execute(emitter: EventEmitter, {
|
||||||
dest = 'build',
|
dest = 'build',
|
||||||
app = 'app',
|
app = 'app',
|
||||||
|
legacy,
|
||||||
bundler,
|
bundler,
|
||||||
webpack = 'webpack',
|
webpack = 'webpack',
|
||||||
rollup = 'rollup',
|
rollup = 'rollup',
|
||||||
@@ -57,7 +56,7 @@ async function execute(emitter: EventEmitter, {
|
|||||||
// create app/manifest/client.js and app/manifest/server.js
|
// create app/manifest/client.js and app/manifest/server.js
|
||||||
create_main_manifests({ bundler, routes: route_objects });
|
create_main_manifests({ bundler, routes: route_objects });
|
||||||
|
|
||||||
const { client, server, serviceworker } = create_compilers(validate_bundler(bundler), { webpack, rollup });
|
const { client, server, serviceworker } = create_compilers(bundler, { webpack, rollup });
|
||||||
|
|
||||||
const client_result = await client.compile();
|
const client_result = await client.compile();
|
||||||
emitter.emit('build', <events.BuildEvent>{
|
emitter.emit('build', <events.BuildEvent>{
|
||||||
@@ -66,11 +65,34 @@ async function execute(emitter: EventEmitter, {
|
|||||||
result: client_result
|
result: client_result
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(path.join(dest, 'build.json'), JSON.stringify({
|
const build_info: {
|
||||||
|
bundler: string;
|
||||||
|
shimport: string;
|
||||||
|
assets: Record<string, string>;
|
||||||
|
legacy_assets?: Record<string, string>;
|
||||||
|
} = {
|
||||||
bundler,
|
bundler,
|
||||||
shimport: bundler === 'rollup' && require('shimport/package.json').version,
|
shimport: bundler === 'rollup' && require('shimport/package.json').version,
|
||||||
assets: client_result.assets
|
assets: client_result.assets
|
||||||
}));
|
};
|
||||||
|
|
||||||
|
if (legacy) {
|
||||||
|
process.env.SAPPER_LEGACY_BUILD = 'true';
|
||||||
|
const { client } = create_compilers(bundler, { webpack, rollup });
|
||||||
|
|
||||||
|
const client_result = await client.compile();
|
||||||
|
|
||||||
|
emitter.emit('build', <events.BuildEvent>{
|
||||||
|
type: 'client (legacy)',
|
||||||
|
// TODO duration/warnings
|
||||||
|
result: client_result
|
||||||
|
});
|
||||||
|
|
||||||
|
build_info.legacy_assets = client_result.assets;
|
||||||
|
delete process.env.SAPPER_LEGACY_BUILD;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(dest, 'build.json'), JSON.stringify(build_info));
|
||||||
|
|
||||||
const server_stats = await server.compile();
|
const server_stats = await server.compile();
|
||||||
emitter.emit('build', <events.BuildEvent>{
|
emitter.emit('build', <events.BuildEvent>{
|
||||||
|
|||||||
@@ -31,8 +31,13 @@ prog.command('build [dest]')
|
|||||||
.describe('Create a production-ready version of your app')
|
.describe('Create a production-ready version of your app')
|
||||||
.option('-p, --port', 'Default of process.env.PORT', '3000')
|
.option('-p, --port', 'Default of process.env.PORT', '3000')
|
||||||
.option('--bundler', 'Specify a bundler (rollup or webpack, blank for auto)')
|
.option('--bundler', 'Specify a bundler (rollup or webpack, blank for auto)')
|
||||||
|
.option('--legacy', 'Create separate legacy build')
|
||||||
.example(`build custom-dir -p 4567`)
|
.example(`build custom-dir -p 4567`)
|
||||||
.action(async (dest = 'build', opts: { port: string, bundler?: string }) => {
|
.action(async (dest = 'build', opts: {
|
||||||
|
port: string,
|
||||||
|
legacy: boolean,
|
||||||
|
bundler?: string
|
||||||
|
}) => {
|
||||||
console.log(`> Building...`);
|
console.log(`> Building...`);
|
||||||
|
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
||||||
@@ -78,9 +83,11 @@ prog.command('export [dest]')
|
|||||||
.option('--build-dir', 'Specify a custom temporary build directory', '.sapper/prod')
|
.option('--build-dir', 'Specify a custom temporary build directory', '.sapper/prod')
|
||||||
.option('--basepath', 'Specify a base path')
|
.option('--basepath', 'Specify a base path')
|
||||||
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
||||||
|
.option('--legacy', 'Create separate legacy build')
|
||||||
.option('--bundler', 'Specify a bundler (rollup or webpack, blank for auto)')
|
.option('--bundler', 'Specify a bundler (rollup or webpack, blank for auto)')
|
||||||
.action(async (dest = 'export', opts: {
|
.action(async (dest = 'export', opts: {
|
||||||
build: boolean,
|
build: boolean,
|
||||||
|
legacy: boolean,
|
||||||
bundler?: string,
|
bundler?: string,
|
||||||
'build-dir': string,
|
'build-dir': string,
|
||||||
basepath?: string,
|
basepath?: string,
|
||||||
|
|||||||
@@ -4,15 +4,20 @@ import { locations } from '../config';
|
|||||||
import validate_bundler from './utils/validate_bundler';
|
import validate_bundler from './utils/validate_bundler';
|
||||||
import { repeat } from '../utils';
|
import { repeat } from '../utils';
|
||||||
|
|
||||||
export function build(opts: { bundler?: string }) {
|
export function build(opts: { bundler?: string, legacy?: boolean }) {
|
||||||
const bundler = validate_bundler(opts.bundler);
|
const bundler = validate_bundler(opts.bundler);
|
||||||
|
|
||||||
|
if (opts.legacy && bundler === 'webpack') {
|
||||||
|
throw new Error(`Legacy builds are not supported for projects using webpack`);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((fulfil, reject) => {
|
return new Promise((fulfil, reject) => {
|
||||||
try {
|
try {
|
||||||
const emitter = _build({
|
const emitter = _build({
|
||||||
dest: locations.dest(),
|
dest: locations.dest(),
|
||||||
app: locations.app(),
|
app: locations.app(),
|
||||||
routes: locations.routes(),
|
routes: locations.routes(),
|
||||||
|
legacy: opts.legacy,
|
||||||
bundler,
|
bundler,
|
||||||
webpack: 'webpack',
|
webpack: 'webpack',
|
||||||
rollup: 'rollup'
|
rollup: 'rollup'
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
output: () => {
|
output: () => {
|
||||||
|
let dir = `${locations.dest()}/client`;
|
||||||
|
if (process.env.SAPPER_LEGACY_BUILD) dir += `/legacy`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dir: `${locations.dest()}/client`,
|
dir,
|
||||||
entryFileNames: '[name].[hash].js',
|
entryFileNames: '[name].[hash].js',
|
||||||
chunkFileNames: '[name].[hash].js',
|
chunkFileNames: '[name].[hash].js',
|
||||||
format: 'esm'
|
format: 'esm'
|
||||||
|
|||||||
Reference in New Issue
Block a user