Improve internal API

This commit is contained in:
Rich Harris
2018-10-08 19:21:15 -04:00
committed by GitHub
parent 5e59855a15
commit 52f40f9e63
46 changed files with 696 additions and 1091 deletions

View File

@@ -1,6 +1,7 @@
import * as path from 'path';
import RollupCompiler from './RollupCompiler';
import { WebpackCompiler } from './WebpackCompiler';
import { set_dev, set_src, set_dest } from '../../config/env';
export type Compiler = RollupCompiler | WebpackCompiler;
@@ -10,9 +11,19 @@ export type Compilers = {
serviceworker?: Compiler;
}
export default async function create_compilers(bundler: 'rollup' | 'webpack'): Promise<Compilers> {
export default async function create_compilers(
bundler: 'rollup' | 'webpack',
cwd: string,
src: string,
dest: string,
dev: boolean
): Promise<Compilers> {
set_dev(dev);
set_src(src);
set_dest(dest);
if (bundler === 'rollup') {
const config = await RollupCompiler.load_config();
const config = await RollupCompiler.load_config(cwd);
validate_config(config, 'rollup');
normalize_rollup_config(config.client);
@@ -30,7 +41,7 @@ export default async function create_compilers(bundler: 'rollup' | 'webpack'): P
}
if (bundler === 'webpack') {
const config = require(path.resolve('webpack.config.js'));
const config = require(path.resolve(cwd, 'webpack.config.js'));
validate_config(config, 'webpack');
return {