-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle webpack in state machine (#25815)
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
- Loading branch information
Showing
13 changed files
with
141 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Compiler } from "webpack" | ||
import { InvokeCallback } from "xstate" | ||
import reporter from "gatsby-cli/lib/reporter" | ||
|
||
export const createWebpackWatcher = (compiler: Compiler): InvokeCallback => ( | ||
callback | ||
): void => { | ||
compiler.hooks.invalid.tap(`file invalidation`, file => { | ||
reporter.verbose(`Webpack file changed: ${file}`) | ||
callback({ type: `SOURCE_FILE_CHANGED`, file }) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import { IBuildContext } from "./types" | ||
import { Stats } from "webpack" | ||
import reporter from "gatsby-cli/lib/reporter" | ||
import { emitter } from "../redux" | ||
|
||
export async function recompile({ | ||
webpackWatching, | ||
}: IBuildContext): Promise<Stats> { | ||
if (!webpackWatching) { | ||
reporter.panic(`Missing compiler`) | ||
} | ||
// Promisify the event-based API. We do this using emitter | ||
// because you can't "untap" a webpack watcher, and we just want | ||
// one compilation. | ||
|
||
return new Promise(resolve => { | ||
function finish(stats: Stats): void { | ||
emitter.off(`COMPILATION_DONE`, finish) | ||
resolve(stats) | ||
} | ||
emitter.on(`COMPILATION_DONE`, finish) | ||
webpackWatching.resume() | ||
// Suspending is just a flag, so it's safe to re-suspend right away | ||
webpackWatching.suspend() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters