diff --git a/greenwood.config.js b/greenwood.config.js index e913c0891..45f4a3b14 100644 --- a/greenwood.config.js +++ b/greenwood.config.js @@ -15,11 +15,11 @@ export default { staticRouter: true, interpolateFrontmatter: true, plugins: [ - ...greenwoodPluginGraphQL(), - ...greenwoodPluginPolyfills(), + greenwoodPluginGraphQL(), + greenwoodPluginPolyfills(), greenwoodPluginPostCss(), - ...greenwoodPluginImportJson(), - ...greenwoodPluginImportCss(), + greenwoodPluginImportJson(), + greenwoodPluginImportCss(), { type: 'rollup', name: 'rollup-plugin-analyzer', @@ -34,7 +34,7 @@ export default { ]; } }, - ...greenwoodPluginIncludeHTML(), + greenwoodPluginIncludeHTML(), ...greenwoodPluginRendererPuppeteer() ], markdown: { diff --git a/packages/cli/src/commands/build.js b/packages/cli/src/commands/build.js index 27f78eaf5..e5ce43348 100644 --- a/packages/cli/src/commands/build.js +++ b/packages/cli/src/commands/build.js @@ -11,10 +11,7 @@ const runProductionBuild = async (compilation) => { try { const { prerender } = compilation.config; const outputDir = compilation.context.outputDir; - const defaultPrerender = (compilation.config.plugins.filter(plugin => plugin.type === 'renderer' && plugin.isGreenwoodDefaultPlugin) || []).length === 1 - ? compilation.config.plugins.filter(plugin => plugin.type === 'renderer')[0].provider(compilation) - : {}; - const customPrerender = (compilation.config.plugins.filter(plugin => plugin.type === 'renderer' && !plugin.isGreenwoodDefaultPlugin) || []).length === 1 + const prerenderPlugin = (compilation.config.plugins.filter(plugin => plugin.type === 'renderer') || []).length === 1 ? compilation.config.plugins.filter(plugin => plugin.type === 'renderer')[0].provider(compilation) : {}; @@ -22,7 +19,7 @@ const runProductionBuild = async (compilation) => { fs.mkdirSync(outputDir); } - if (prerender || customPrerender.prerender) { + if (prerender || prerenderPlugin.prerender) { // start any servers if needed const servers = [...compilation.config.plugins.filter((plugin) => { return plugin.type === 'server'; @@ -42,14 +39,10 @@ const runProductionBuild = async (compilation) => { return Promise.resolve(server); })); - if (customPrerender.workerUrl) { - await preRenderCompilationWorker(compilation, customPrerender); - } else if (customPrerender.customUrl) { - await preRenderCompilationCustom(compilation, customPrerender); - } else if (defaultPrerender && prerender) { - await preRenderCompilationWorker(compilation, defaultPrerender); + if (prerenderPlugin.workerUrl) { + await preRenderCompilationWorker(compilation, prerenderPlugin); } else { - reject('This is an unhandled pre-rendering case! Please report.'); + await preRenderCompilationCustom(compilation, prerenderPlugin); } } else { await staticRenderCompilation(compilation); diff --git a/packages/cli/src/lifecycles/config.js b/packages/cli/src/lifecycles/config.js index 53ccbb06b..7e5ad7301 100644 --- a/packages/cli/src/lifecycles/config.js +++ b/packages/cli/src/lifecycles/config.js @@ -100,31 +100,38 @@ const readAndMergeConfig = async() => { if (plugins && plugins.length > 0) { plugins.forEach(plugin => { - if (!plugin.type || pluginTypes.indexOf(plugin.type) < 0) { - reject(`Error: greenwood.config.js plugins must be one of type "${pluginTypes.join(', ')}". got "${plugin.type}" instead.`); - } + const flattened = (Array.isArray(plugin) ? plugin : [plugin]).flat(); - if (!plugin.provider || typeof plugin.provider !== 'function') { - const providerTypeof = typeof plugin.provider; + flattened.forEach(plugin => { + if (!plugin.type || pluginTypes.indexOf(plugin.type) < 0) { + reject(`Error: greenwood.config.js plugins must be one of type "${pluginTypes.join(', ')}". got "${plugin.type}" instead.`); + } - reject(`Error: greenwood.config.js plugins provider must be a function. got ${providerTypeof} instead.`); - } + if (!plugin.provider || typeof plugin.provider !== 'function') { + const providerTypeof = typeof plugin.provider; - if (!plugin.name || typeof plugin.name !== 'string') { - const nameTypeof = typeof plugin.name; + reject(`Error: greenwood.config.js plugins provider must be a function. got ${providerTypeof} instead.`); + } - reject(`Error: greenwood.config.js plugins must have a name. got ${nameTypeof} instead.`); - } + if (!plugin.name || typeof plugin.name !== 'string') { + const nameTypeof = typeof plugin.name; + + reject(`Error: greenwood.config.js plugins must have a name. got ${nameTypeof} instead.`); + } + }); + + customConfig.plugins = [ + ...customConfig.plugins, + ...flattened + ]; }); - // if user provides a custom renderer, replace ours with theirs - if (plugins.filter(plugin => plugin.type === 'renderer').length === 1) { + // if user provided a custom renderer, filter out Greenwood's default renderer + if (customConfig.plugins.filter(plugin => plugin.type === 'renderer').length > 1) { customConfig.plugins = customConfig.plugins.filter((plugin) => { - return plugin.type !== 'renderer'; + return plugin.type !== 'renderer' || plugin.type === 'renderer' && !plugin.isGreenwoodDefaultPlugin; }); } - - customConfig.plugins = customConfig.plugins.concat(plugins); } if (devServer && Object.keys(devServer).length > 0) {