give manifest searching a function

This commit is contained in:
Erin 2023-07-28 04:41:15 -04:00
parent bb79e2a059
commit cb948b82ba

View file

@ -46,6 +46,8 @@ export function createConfig (manifestPathRelative, options, createConfig) {
return join(outputDir, platform, getOutputFilename(entryPath, ext));
}
/** Scans a manifest for entrypoints */
function getEntryPointsFromManifest (manifestContent) {
const scriptEntrypointAbsolutePaths = [];
const styleEntrypointAbsolutePathss = [];
const otherAssetAbsolutePaths = [];
@ -95,9 +97,18 @@ export function createConfig (manifestPathRelative, options, createConfig) {
}
});
return {
scripts: scriptEntrypointAbsolutePaths,
styles: styleEntrypointAbsolutePathss,
assets: otherAssetAbsolutePaths,
};
}
const {scripts, styles, assets} = getEntryPointsFromManifest(manifestContent);
const platform = 'firefox';
return [
...scriptEntrypointAbsolutePaths.map(entrypointPath => ({
...scripts.map(entrypointPath => ({
// Get configuration options for this entrypoint from the caller
...createConfig(),
// Overwrite input and output options
@ -119,14 +130,14 @@ export function createConfig (manifestPathRelative, options, createConfig) {
plugins: [
{
buildStart () {
styleEntrypointAbsolutePathss.forEach(absolutePath => {
styles.forEach(absolutePath => {
this.emitFile({
type: 'asset',
fileName: getOutputFilename(absolutePath, 'css'),
source: readFileSync(absolutePath, {encoding: 'utf-8'}),
});
});
otherAssetAbsolutePaths.forEach(absolutePath => {
assets.forEach(absolutePath => {
// console.log('rendering binary file', absolutePath);
this.emitFile({
type: 'asset',