MCPcopy
hub / github.com/web-infra-dev/rsbuild / build

Function build

e2e/helper/jsApi.ts:179–247  ·  view source on GitHub ↗
({
  catchBuildError = false,
  runServer = false,
  watch = false,
  page,
  logHelper,
  ...options
}: BuildOptions = {})

Source from the content-addressed store, hash-verified

177 * Build the project and return the build result.
178 */
179export async function build({
180 catchBuildError = false,
181 runServer = false,
182 watch = false,
183 page,
184 logHelper,
185 ...options
186}: BuildOptions = {}) {
187 process.env.NODE_ENV = 'production';
188
189 options.config = await updateConfigForTest(options.config || {}, options.cwd);
190
191 const rsbuild = await createRsbuild(options);
192 const getOutputFiles = collectOutputFiles(rsbuild);
193
194 let buildError: Error | undefined;
195 let buildResult: RsbuildBuildResult | undefined;
196
197 try {
198 buildResult = await rsbuild.build({ watch });
199 } catch (error) {
200 buildError = error as Error;
201 buildError.message = stripAnsi(buildError.message);
202
203 if (!catchBuildError) {
204 throw buildError;
205 }
206 }
207
208 const { distPath } = rsbuild.context;
209
210 let port = 0;
211 let server = { close: noop };
212
213 if (runServer || page) {
214 const result = await rsbuild.preview();
215 port = result.port;
216 server = result.server;
217 }
218
219 const getIndexBundle = async () => {
220 const [name, content] =
221 Object.entries(getOutputFiles()).find(
222 ([file]) => file.includes('index') && file.endsWith('.js'),
223 ) || [];
224 assert(name && content);
225 return content;
226 };
227
228 if (page) {
229 await gotoPage(page, { port });
230 }
231
232 return {
233 ...logHelper!,
234 distPath,
235 port,
236 stats: buildResult?.stats,

Callers 15

index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50
index.test.tsFile · 0.50

Calls 6

createRsbuildFunction · 0.90
gotoPageFunction · 0.90
updateConfigForTestFunction · 0.85
collectOutputFilesFunction · 0.85
filterSourceMapsFunction · 0.85
closeMethod · 0.45

Tested by 4

buildFixtureFunction · 0.40
buildAndReadFunction · 0.40
buildWithExtractFunction · 0.40
testSourceMapTypeFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…