MCPcopy
hub / github.com/react/create-react-app / createCompiler

Function createCompiler

packages/react-dev-utils/WebpackDevServerUtils.js:103–230  ·  view source on GitHub ↗
({
  appName,
  config,
  urls,
  useYarn,
  useTypeScript,
  webpack,
})

Source from the content-addressed store, hash-verified

101}
102
103function createCompiler({
104 appName,
105 config,
106 urls,
107 useYarn,
108 useTypeScript,
109 webpack,
110}) {
111 // "Compiler" is a low-level interface to webpack.
112 // It lets us listen to some events and provide our own custom messages.
113 let compiler;
114 try {
115 compiler = webpack(config);
116 } catch (err) {
117 console.log(chalk.red('Failed to compile.'));
118 console.log();
119 console.log(err.message || err);
120 console.log();
121 process.exit(1);
122 }
123
124 // "invalid" event fires when you have changed a file, and webpack is
125 // recompiling a bundle. WebpackDevServer takes care to pause serving the
126 // bundle, so if you refresh, it'll wait instead of serving the old one.
127 // "invalid" is short for "bundle invalidated", it doesn't imply any errors.
128 compiler.hooks.invalid.tap('invalid', () => {
129 if (isInteractive) {
130 clearConsole();
131 }
132 console.log('Compiling...');
133 });
134
135 let isFirstCompile = true;
136 let tsMessagesPromise;
137
138 if (useTypeScript) {
139 forkTsCheckerWebpackPlugin
140 .getCompilerHooks(compiler)
141 .waiting.tap('awaitingTypeScriptCheck', () => {
142 console.log(
143 chalk.yellow(
144 'Files successfully emitted, waiting for typecheck results...'
145 )
146 );
147 });
148 }
149
150 // "done" event fires when webpack has finished recompiling the bundle.
151 // Whether or not you have warnings or errors, you will get this event.
152 compiler.hooks.done.tap('done', async stats => {
153 if (isInteractive) {
154 clearConsole();
155 }
156
157 // We have switched off the default webpack output in WebpackDevServer
158 // options so we are going to "massage" the warnings and errors and present
159 // them in a readable focused way.
160 // We only construct the warnings and errors for speed:

Callers 1

start.jsFile · 0.85

Calls 3

clearConsoleFunction · 0.85
formatWebpackMessagesFunction · 0.70
printInstructionsFunction · 0.70

Tested by

no test coverage detected