From 3dfd106d3d08ceb30b873c96a4479c8c53b66e00 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Thu, 18 Feb 2021 15:17:16 -0500 Subject: [PATCH] restore optimization --- packages/cli/src/config/rollup.config.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/config/rollup.config.js b/packages/cli/src/config/rollup.config.js index e4679d1f0..19bcc76bf 100644 --- a/packages/cli/src/config/rollup.config.js +++ b/packages/cli/src/config/rollup.config.js @@ -97,7 +97,7 @@ function greenwoodWorkspaceResolver (compilation) { // https://github.com/rollup/rollup/issues/2873 function greenwoodHtmlPlugin(compilation) { - const { userWorkspace, outputDir, scratchDir } = compilation.context; + const { userWorkspace, outputDir, scratchDir } = compilation.context; const customResources = compilation.config.plugins.filter((plugin) => { return plugin.type === 'resource'; }).map((plugin) => { @@ -367,12 +367,10 @@ function greenwoodHtmlPlugin(compilation) { } }, - writeBundle(outputOptions, bundles) { - // TODO looping over bundles twice is wildly inneficient, should refactor and safe references once + async writeBundle(outputOptions, bundles) { for (const bundleId of Object.keys(bundles)) { const bundle = bundles[bundleId]; - // TODO handle (!) Generated empty chunks .greenwood/about, .greenwood/index if (bundle.isEntry && path.extname(bundle.facadeModuleId) === '.html') { // TODO this seems hacky; hardcoded dirs :D const htmlPath = bundle.facadeModuleId.replace('.greenwood', 'public'); @@ -421,6 +419,11 @@ function greenwoodHtmlPlugin(compilation) { }); fs.writeFileSync(htmlPath, html); + } else { + const sourcePath = `${outputDir}/${bundleId}`; + const optimizedSource = await getOptimizedSource(sourcePath, customResources, compilation); + + await fs.promises.writeFile(sourcePath, optimizedSource); } } }