Skip to content

Commit

Permalink
fix: plug into async method
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 29, 2020
1 parent 015f5a7 commit b2ced9a
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions integrations/nextjs-plugin/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CompileProps } from '@component-controls/webpack-configs';

const defaultPresets = ['react', 'react-docgen-typescript'];

let builtStarted = false;
export default ({
bundleName,
configPath,
Expand All @@ -13,29 +12,33 @@ export default ({
webPack,
...rest
}: CompileProps) => (phase: string, nextConfig: any) => {
const { defaultConfig } = nextConfig;
const userProps: CompileProps = {
bundleName,
configPath,
webPack,
};
const options: CompileProps = {
presets: presets || defaultPresets,
distFolder: path.resolve(__dirname),
staticFolder:
staticFolder || path.join(process.cwd(), defaultConfig.distDir),
...userProps,
};

if (phase !== 'phase-export' && !builtStarted) {
builtStarted = true;
const compiler =
process.env.NODE_ENV === 'development'
? watch(options)
: compile(options);
compiler.then(() => {});
}
return {
/**
* we need some async function, to make sure the compilation process is completed
*/
async headers() {
const { defaultConfig } = nextConfig;
const userProps: CompileProps = {
bundleName,
configPath,
webPack,
};
const options: CompileProps = {
presets: presets || defaultPresets,
distFolder: path.resolve(__dirname),
staticFolder:
staticFolder || path.join(process.cwd(), defaultConfig.distDir),
...userProps,
};

const compiler =
process.env.NODE_ENV === 'development'
? watch(options)
: compile(options);
await compiler;

return [];
},
...rest,
};
};

0 comments on commit b2ced9a

Please sign in to comment.