mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Create getEntries function
This commit is contained in:
parent
b3ec030bb7
commit
64b08e853b
35
src/index.js
35
src/index.js
@ -83,27 +83,27 @@ export default async function microbundle(inputOptions) {
|
||||
pkgName: options.pkg.name,
|
||||
});
|
||||
|
||||
let entries = (await map([].concat(options.input), async file => {
|
||||
file = resolve(cwd, file);
|
||||
if (await isDir(file)) {
|
||||
file = resolve(file, 'index.js');
|
||||
}
|
||||
return file;
|
||||
})).filter((item, i, arr) => arr.indexOf(item) === i);
|
||||
options.entries = await getEntries({
|
||||
cwd,
|
||||
input: options.input,
|
||||
});
|
||||
|
||||
options.entries = entries;
|
||||
|
||||
options.multipleEntries = entries.length > 1;
|
||||
options.multipleEntries = options.entries.length > 1;
|
||||
|
||||
let formats = (options.format || options.formats).split(',');
|
||||
// always compile cjs first if it's there:
|
||||
formats.sort((a, b) => (a === 'cjs' ? -1 : a > b ? 1 : 0));
|
||||
|
||||
let steps = [];
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
for (let i = 0; i < options.entries.length; i++) {
|
||||
for (let j = 0; j < formats.length; j++) {
|
||||
steps.push(
|
||||
createConfig(options, entries[i], formats[j], i === 0 && j === 0),
|
||||
createConfig(
|
||||
options,
|
||||
options.entries[i],
|
||||
formats[j],
|
||||
i === 0 && j === 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -266,6 +266,17 @@ async function getOutput({ cwd, output, pkgMain, pkgName }) {
|
||||
return main;
|
||||
}
|
||||
|
||||
async function getEntries({ input, cwd }) {
|
||||
let entries = (await map([].concat(input), async file => {
|
||||
file = resolve(cwd, file);
|
||||
if (await isDir(file)) {
|
||||
file = resolve(file, 'index.js');
|
||||
}
|
||||
return file;
|
||||
})).filter((item, i, arr) => arr.indexOf(item) === i);
|
||||
return entries;
|
||||
}
|
||||
|
||||
function createConfig(options, entry, format, writeMeta) {
|
||||
let { pkg } = options;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user