diff --git a/packages/cli/src/config/rollup.config.js b/packages/cli/src/config/rollup.config.js index 8aa6f56c2..823aef2cf 100644 --- a/packages/cli/src/config/rollup.config.js +++ b/packages/cli/src/config/rollup.config.js @@ -355,31 +355,29 @@ const getRollupConfigForScriptResources = async (compilation) => { const getRollupConfigForApis = async (compilation) => { const { outputDir, userWorkspace } = compilation.context; - const input = [...compilation.manifest.apis.values()] - .map(api => normalizePathnameForWindows(new URL(`.${api.path}`, userWorkspace))); // why is this needed? await fs.promises.mkdir(new URL('./api/assets/', outputDir), { recursive: true }); - // TODO should routes and APIs have chunks? - // https://github.com/ProjectEvergreen/greenwood/issues/1118 - return [{ - input, - output: { - dir: `${normalizePathnameForWindows(outputDir)}/api`, - entryFileNames: '[name].js', - chunkFileNames: '[name].[hash].js' - }, - plugins: [ - greenwoodJsonLoader(), - greenwoodResourceLoader(compilation), - nodeResolve(), - commonjs(), - greenwoodImportMetaUrl(compilation) - ] - }]; + return [...compilation.manifest.apis.values()] + .map(api => normalizePathnameForWindows(new URL(`.${api.path}`, userWorkspace))) + .map(filepath => ({ + input: filepath, + output: { + dir: `${normalizePathnameForWindows(outputDir)}/api`, + entryFileNames: '[name].js', + chunkFileNames: '[name].[hash].js' + }, + plugins: [ + greenwoodJsonLoader(), + greenwoodResourceLoader(compilation), + nodeResolve(), + commonjs(), + greenwoodImportMetaUrl(compilation) + ] + })); }; const getRollupConfigForSsr = async (compilation, input) => { diff --git a/packages/cli/src/lifecycles/bundle.js b/packages/cli/src/lifecycles/bundle.js index e5a28fdd5..1620039dd 100644 --- a/packages/cli/src/lifecycles/bundle.js +++ b/packages/cli/src/lifecycles/bundle.js @@ -163,11 +163,13 @@ async function bundleStyleResources(compilation, resourcePlugins) { async function bundleApiRoutes(compilation) { // https://rollupjs.org/guide/en/#differences-to-the-javascript-api - const [rollupConfig] = await getRollupConfigForApis(compilation); + const apiConfigs = await getRollupConfigForApis(compilation); - if (rollupConfig.input.length !== 0) { - const bundle = await rollup(rollupConfig); - await bundle.write(rollupConfig.output); + if (apiConfigs.length > 0 && apiConfigs[0].input.length !== 0) { + apiConfigs.forEach(async rollupConfig => { + const bundle = await rollup(rollupConfig); + await bundle.write(rollupConfig.output); + }); } }