mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 03:25:24 +00:00
add a --bundler option, for forcing rollup or webpack
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { build as _build } from '../api/build';
|
||||
import colors from 'kleur';
|
||||
import * as colors from 'kleur';
|
||||
import { locations } from '../config';
|
||||
import validate_bundler from './utils/validate_bundler';
|
||||
|
||||
export function build(opts: { bundler?: string }) {
|
||||
const bundler = validate_bundler(opts.bundler);
|
||||
|
||||
export function build() {
|
||||
return new Promise((fulfil, reject) => {
|
||||
try {
|
||||
const emitter = _build({
|
||||
dest: locations.dest(),
|
||||
app: locations.app(),
|
||||
routes: locations.routes(),
|
||||
bundler,
|
||||
webpack: 'webpack',
|
||||
rollup: 'rollup'
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import prettyMs from 'pretty-ms';
|
||||
import { dev as _dev } from '../api/dev';
|
||||
import * as events from '../api/interfaces';
|
||||
|
||||
export function dev(opts: { port: number, open: boolean }) {
|
||||
export function dev(opts: { port: number, open: boolean, bundler?: string }) {
|
||||
try {
|
||||
const watcher = _dev(opts);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { exporter as _exporter } from '../api/export';
|
||||
import colors from 'kleur';
|
||||
import * as colors from 'kleur';
|
||||
import prettyBytes from 'pretty-bytes';
|
||||
import { locations } from '../config';
|
||||
|
||||
|
||||
21
src/cli/utils/validate_bundler.ts
Normal file
21
src/cli/utils/validate_bundler.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as fs from 'fs';
|
||||
|
||||
export default function validate_bundler(bundler?: string) {
|
||||
if (!bundler) {
|
||||
bundler = (
|
||||
fs.existsSync('rollup') ? 'rollup' :
|
||||
fs.existsSync('webpack') ? 'webpack' :
|
||||
null
|
||||
);
|
||||
|
||||
if (!bundler) {
|
||||
throw new Error(`Could not find a 'rollup' or 'webpack' directory`);
|
||||
}
|
||||
}
|
||||
|
||||
if (bundler !== 'rollup' && bundler !== 'webpack') {
|
||||
throw new Error(`'${bundler}' is not a valid option for --bundler — must be either 'rollup' or 'webpack'`);
|
||||
}
|
||||
|
||||
return bundler;
|
||||
}
|
||||
Reference in New Issue
Block a user