add a --bundler option, for forcing rollup or webpack

This commit is contained in:
Rich Harris
2018-08-28 17:29:14 -04:00
parent 6e2383b66b
commit 85e25d6380
8 changed files with 45 additions and 11 deletions

View File

@@ -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'
});

View File

@@ -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);

View File

@@ -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';

View 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;
}