Automatically detect and use index.ts & src/index.ts entry rather than requiring it to be manually specified.

This commit is contained in:
Jason Miller 2018-01-23 14:52:55 -05:00
parent 7db4d5c2e7
commit 236fa3f4de

View File

@ -55,9 +55,11 @@ export default async function microbundle(options) {
}
}
const jsOrTs = async filename => resolve(cwd, `${filename}${await isFile(resolve(cwd, filename+'.ts')) ? '.ts' : '.js'}`);
options.input = [];
[].concat(
options.entries && options.entries.length ? options.entries : options.pkg.source || (await isDir(resolve(cwd, 'src')) && 'src/index.js') || (await isFile(resolve(cwd, 'index.js')) && 'index.js') || options.pkg.module
options.entries && options.entries.length ? options.entries : options.pkg.source || (await isDir(resolve(cwd, 'src')) && await jsOrTs('src/index')) || await jsOrTs('index') || options.pkg.module
).map( file => glob.sync(resolve(cwd, file)) ).forEach( file => options.input.push(...file) );
let main = resolve(cwd, options.output || options.pkg.main || 'dist');