1"use strict";(self.webpackChunkfarm_docs=self.webpackChunkfarm_docs||[]).push([[2936],{26523:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>l,default:()=>h,frontMatter:()=>c,metadata:()=>t,toc:()=>d});var i=n(49214),s=n(36906),a=n(37620);const c={},l="Javascript Api",t={id:"api/javascript-api",title:"Javascript Api",description:"Farm provides a comprehensive set of APIs for development servers, compilers, watchers, etc. Developers can use these APIs by importing the @farmfe/core package.",source:"@site/docs/api/javascript-api.mdx",sourceDirName:"api",slug:"/api/javascript-api",permalink:"/docs/api/javascript-api",draft:!1,unlisted:!1,editUrl:"https://github.com/farm-fe/farm-fe.github.io/tree/main/docs/api/javascript-api.mdx",tags:[],version:"current",frontMatter:{},sidebar:"apiSidebar",previous:{title:"Runtime Plugin API",permalink:"/docs/api/runtime-plugin-api"},next:{title:"Rust Api",permalink:"/docs/api/rust-api"}},o={},d=[{value:"Start",id:"start",level:2},{value:"Build",id:"build",level:2},{value:"Watch",id:"watch",level:2},{value:"Preview",id:"preview",level:2},{value:"Clean",id:"clean",level:2},{value:"loadEnv",id:"loadenv",level:2},{value:"createDevServer",id:"createdevserver",level:2},{value:"createPreviewServer",id:"createpreviewserver",level:2},{value:"getCompiler",id:"getcompiler",level:2},{value:"close",id:"close",level:2},{value:"Compiler",id:"compiler",level:2},{value:"compile",id:"compile",level:3},{value:"compileSync",id:"compilesync",level:3},{value:"traceDependencies",id:"tracedependencies",level:3},{value:"update",id:"update",level:3},{value:"hasModule",id:"hasmodule",level:3},{value:"getParentFiles",id:"getparentfiles",level:3},{value:"resources",id:"resources",level:3},{value:"Resource",id:"resource",level:3},{value:"writeResourcesToDisk",id:"writeresourcestodisk",level:3},{value:"removeOutputPathDir",id:"removeoutputpathdir",level:3},{value:"resolvedWatchPaths",id:"resolvedwatchpaths",level:3},{value:"resolvedModulePaths",id:"resolvedmodulepaths",level:3},{value:"onUpdateFinish",id:"onupdatefinish",level:3},{value:"outputPath",id:"outputpath",level:3},{value:"addExtraWatchFile",id:"addextrawatchfile",level:3},{value:"modules",id:"modules",level:3}];function p(e){const r={admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.header,{children:(0,i.jsx)(r.h1,{id:"javascript-api",children:"Javascript Api"})}),"\n",(0,i.jsxs)(r.p,{children:[(0,i.jsx)(r.code,{children:"Farm"})," provides a comprehensive set of APIs for development servers, compilers, watchers, etc. Developers can use these APIs by importing the ",(0,i.jsx)(r.code,{children:"@farmfe/core"})," package."]}),"\n",(0,i.jsxs)(r.p,{children:["Install the ",(0,i.jsx)(r.code,{children:"@farmfe/core"})," package:"]}),"\n",(0,i.jsx)(a.k,{command:"pnpm add @farmfe/core@latest"}),"\n",(0,i.jsx)(r.h2,{id:"start",children:"Start"}),"\n",(0,i.jsxs)(r.p,{children:["The ",(0,i.jsx)(r.code,{children:"start"})," method is used to quickly launch the development server."]}),"\n",(0,i.jsxs)(r.p,{children:["After calling the ",(0,i.jsx)(r.code,{children:"start"})," method, you can see the log information of the available ",(0,i.jsx)(r.code,{children:"ip"})," address in the current console. By default, it compiles the ",(0,i.jsx)(r.code,{children:"index.html"})," file in the current directory."]}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"start(options: InlineConfig): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { start, logger } from "@farmfe/core";\ntry {\n await start({\n compilation: {\n output: {\n publicPath: "/dist"\n },\n input: {\n index: "./base.html"\n }\n },\n server: {\n port: 6532,\n hmr: {\n path: "/__farm_hmr",\n }\n },\n plugins: [\n \'@farmfe/plugin-react\',\n \'@farmfe/plugin-sass\'\n ],\n });\n}
1 catch (error) {\n logger.error(`Failed to start server:\\n ${error.stack}`);\n process.exit(1);\n}\n\n'})}),"\n",(0,i.jsx)(r.p,{children:"another way is use more deep api to start server:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:"import {\n createCompiler,\n createDevServer,\n resolveConfig\n} from '@farmfe/core';\n\nconst resolveUserConfig = await resolveConfig({\n compilation: {\n output: {\n publicPath: \"/dist\"\n },\n input: {\n index: \"./base.html\"\n }\n },\n server: {\n port: 6532,\n hmr: {\n path: \"/__farm_hmr\",\n }\n },\n plugins: [\n '@farmfe/plugin-react',\n '@farmfe/plugin-sass'\n ],\n})\n\n// create compiler\nconst compiler = await createCompiler(resolveUserConfig);\nconst server = await createDevServer(compiler, resolveUserConfig);\nserver.listen();\n"})}),"\n",(0,i.jsx)(r.h2,{id:"build",children:"Build"}),"\n",(0,i.jsx)(r.p,{children:"The build method is used to build for the production environment."}),"\n",(0,i.jsx)(r.p,{children:"After calling the build method, it defaults to building browser artifacts and generates a dist folder in the current directory. If you need to build artifacts for different environments and versions, such as node, node-next, browser, browser-es2017, etc., you can configure it by checking output targetEnv."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"build(options: InlineConfig): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { build, logger } from "@farmfe/core";\ntry {\n await build(options);\n} catch (error) {\n logger.error(`error during build:\\n ${error.stack}`);\n process.exit(1);\n}\n'})}),"\n",(0,i.jsx)(r.h2,{id:"watch",children:"Watch"}),"\n",(0,i.jsx)(r.p,{children:"The watch method provides real-time updates for the compilation of the current project, equivalent to npx farm build --watch. Generally used in the node environment."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"watch(options: InlineConfig): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { watch, logger } from "@farmfe/core";\ntry {\n await watch(defaultOptions);\n} catch (error) {\n logger.error(`error during watch project:\\n ${error.stack}`);\n process.exit(1);\n}\n'})}),"\n",(0,i.jsx)(r.h2,{id:"preview",children:"Preview"}),"\n",(0,i.jsx)(r.p,{children:"The preview method starts a preview server for previewing production artifacts. Make sure to have built the artifacts using the build method and have the correct production artifacts."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"preview(options: InlineConfig): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { preview, logger } from "@farmfe/core";\ntry {\n await preview(defaultOptions);\n} catch (error) {\n logger.error(`Failed to start preview server:\\n ${error.stack}`);\n process.exit(1);\n}\n'})}),"\n",(0,i.jsx)(r.h2,{id:"clean",children:"Clean"}),"\n",(0,i.jsx)(r.p,{children:"The clean method clears the cache generated by the farm incremental build. If you have issues with the incremental build causing crashes due to unforeseen or undiscovered problems, clearing the cache might help."}),"\n",(0,i.jsx)(r.admonition,{type:"warning",children:(0,i.jsx)(r.p,{children:"If there are problems with the incremental build causing crashes that are not resolved by clearing the cache, please submit an issue on GitHub."})}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"clean(options: InlineConfig): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { clean, logger } from "@farmfe/core";\ntry {\n await clean(defaultOptions);\n} catch (error) {\n logger.error(`Failed to clean cache:\\n ${error.stack}`);\n process.exit(1);\n}\n'})}),"\n",(0,i.jsx)(r.h2,{id:"loadenv",children:"loadEnv"}),"\n",(0,i.jsx)(r.p,{children:"Load environment variables from the .env file."}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-ts",children:"type LoadEnvFunc = (\n mode: string,\n envDir: string,\n prefixes: string | string[] = ['FARM_', 'VITE_']\n) => [env: Record<string, string>, existsEnvFiles: string[]];\n"})}),"\n",(0,i.jsxs)(r.ul,{children:["\n",(0,i.jsxs)(r.li,{children:[(0,i.jsx)(r.code,{children:"mode"})," is ",(0,i.jsx)(r.code,{children:"development"}),", ",(0,i.jsx)(r.code,{children:"production"})," or any string. ",(0,i.jsx)(r.code,{children:"loadEnv"})," will try load ",(0,i.jsx)(r.code,{children:"[``.env``, ``.env.local``, ``.env.${mode}``, ``.env.${mode}.local``]"})," for ",(0,i.jsx)(r.code,{children:"envDir"}),"."]}),"\n",(0,i.jsxs)(r.li,{children:[(0,i.jsx)(r.code,{children:"envDir"})," is the directory where the ",(0,i.jsx)(r.code,{children:".env"})," file is located."]}),"\n",(0,i.jsxs)(r.li,{children:[(0,i.jsx)(r.code,{children:"prefixes"})," is the prefix of the environment variable. The default value is ",(0,i.jsx)(r.code,{children:"['FARM_', 'VITE_']"}),". Env variables with these prefixes will be injected into ",(0,i.jsx)(r.code,{children:"define"})," automatically."]}),"\n"]}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-js",children:"const [env, files] = loadEnv('development', '/path/to/project/env');\n// use env\n"})}),"\n",(0,i.jsx)(r.h2,{id:"createdevserver",children:"createDevServer"}),"\n",(0,i.jsx)(r.p,{children:"The createDevServer method is used to start a local development server. You need to instantiate the Server object first and pass the compiler as a parameter."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"createDevServer(options: DevServerOptions): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'import { Server } from "@farmfe/core";\nconst server = new Server();\nawait server.createDevServer(options);\nserver.listen()\n'})}),"\n",(0,i.jsx)(r.h2,{id:"createpreviewserver",children:"createPreviewServer"}),"\n",(0,i.jsx)(r.p,{children:"Create a preview server for previewing production artifacts."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"createPreviewServer(options: DevServerOptions): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Server } from "@farmfe/core";\nconst server = new Server();\nawait server.createPreviewServer(options);\n'})}),"\n",(0,i.jsx)(r.h2,{id:"getcompiler",children:"getCompiler"}),"\n",(0,i.jsx)(r.p,{children:"Get the current development server's compiler instance. Pass the compiler as a parameter when instantiating the Server."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ngetCompiler(): Compiler\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Server, Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst server = new Server({\n compiler\n});\nconst compilerInstance = server.getCompiler();\n'})}),"\n",(0,i.jsx)(r.h2,{id:"close",children:"close"}),"\n",(0,i.jsx)(r.p,{children:"Close all servers and WebSocket services opened by createDevServer."}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Server } from "@farmfe/core";\nconst server = new Server();\nawait server.createDevServer(options);\nserver.listen()\nawait server.close();\n'})}),"\n",(0,i.jsx)(r.h2,{id:"compiler",children:"Compiler"}),"\n",(0,i.jsx)(r.p,{children:"The Compiler provides a set of compiler APIs. You can create a compiler instance by instantiating Compiler."}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"compile",children:"compile"}),"\n",(0,i.jsx)(r.p,{children:"Asynchronously start the compilation process. Returns a Promise."}),"\n",(0,i.jsx)(r.admonition,{type:"note",children:(0,i.jsx)(r.p,{children:"If specific environment variables are set (process.env.FARM_PROFILE), it performs a synchronous compilation."})}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ncompile(): Promise<void>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"compilesync",children:"compileSync"}),"\n",(0,i.jsx)(r.p,{children:"Synchronously start the compilation process."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ncompileSync(): void\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\ncompiler.compileSync();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"tracedependencies",children:"traceDepen
1dencies"}),"\n",(0,i.jsx)(r.p,{children:"Trace dependencies between files. Returns an array of all dependencies for the provided input in the compiler configuration. Useful for restarting compilation based on file dependencies."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ntraceDependencies(): Array<string>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\n\nconst config = {\n input: "./farm.config.js"\n}\nconst compiler = new Compiler(config);\nconst dependencies = compiler.traceDependencies();\n'})}),"\n",(0,i.jsx)(r.p,{children:"Returns an array of paths representing all dependencies."}),"\n",(0,i.jsx)(r.h3,{id:"update",children:"update"}),"\n",(0,i.jsx)(r.p,{children:"Update compilation based on the provided paths. Returns a Promise resolving to a JsUpdateResult. If compilation is already in progress, it waits for completion and updates. If ignoreCompilingCheck is set to true, it won't check the compilation status."}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ntype JsUpdateResult = {\n success: boolean\n errors: Array<Error>\n warnings: Array<Error>\n}\n\nupdate(paths: Array<string>, sync: boolean, ignoreCompilingCheck: boolean): JsUpdateResult\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst result = await compiler.update(paths, true, true);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"hasmodule",children:"hasModule"}),"\n",(0,i.jsx)(r.p,{children:"Pass a path to determine if the current path is within the modules compiled by the compiler."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nhasModule(path: string): boolean\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst result = compiler.hasModule(path);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"getparentfiles",children:"getParentFiles"}),"\n",(0,i.jsx)(r.p,{children:"Retrieve the current file that a module import with the module import name (id) or resolved path identifier (resolvedPath) imports."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ngetParentFiles(resolvedPath: string): Array<string>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst result = compiler.getParentFiles(resolvedPath);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"resources",children:"resources"}),"\n",(0,i.jsx)(r.p,{children:"Return all resources compiled by the compiler."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\ntype Resource = {\n path: string\n buffer: Buffer\n}\nresources(): Array<Resource>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\nconst result = compiler.resources();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"resource",children:"Resource"}),"\n",(0,i.jsx)(r.p,{children:"Return the buffer of the current artifact based on the given file."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nresource(path: string): Buffer | null\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\nconst result = compiler.resource(path);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"writeresourcestodisk",children:"writeResourcesToDisk"}),"\n",(0,i.jsx)(r.p,{children:"Write resources to disk based on the configured output path."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nwriteResourcesToDisk(): void\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\ncompiler.writeResourcesToDisk();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"removeoutputpathdir",children:"removeOutputPathDir"}),"\n",(0,i.jsx)(r.p,{children:"Remove the output path directory."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nremoveOutputPathDir(): void\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\ncompiler.removeOutputPathDir();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"resolvedwatchpaths",children:"resolvedWatchPaths"}),"\n",(0,i.jsx)(r.p,{children:"Return resolved watch paths."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nresolvedWatchPaths(): Array<string>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\nconst result = compiler.resolvedWatchPaths();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"resolvedmodulepaths",children:"resolvedModulePaths"}),"\n",(0,i.jsx)(r.p,{children:"Return resolved module paths relative to the provided root path."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nresolvedModulePaths(rootPath: string): Array<string>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nawait compiler.compile()\nconst result = compiler.resolvedModulePaths(rootPath);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"onupdatefinish",children:"onUpdateFinish"}),"\n",(0,i.jsx)(r.p,{children:"Add a callback to be executed after the update process is complete."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nonUpdateFinish(callback: (...args: any[]) => any): void\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\ncompiler.onUpdateFinish(callback);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"outputpath",children:"outputPath"}),"\n",(0,i.jsx)(r.p,{children:"Return the resolved output path."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\noutputPath(): string\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst result = compiler.outputPath();\n'})}),"\n",(0,i.jsx)(r.h3,{id:"addextrawatchfile",children:"addExtraWatchFile"}
1),"\n",(0,i.jsx)(r.p,{children:"Add extra watch files for the compiler."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\naddExtraWatchFile(rootPath: string, filePath: string[]): void\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\ncompiler.addExtraWatchFile(rootPath, filePath);\n'})}),"\n",(0,i.jsx)(r.h3,{id:"modules",children:"modules"}),"\n",(0,i.jsx)(r.p,{children:"Return an array of objects representing file module resolutions."}),"\n",(0,i.jsx)(r.p,{children:"Type:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-typescript",children:"\nexport interface Module {\n id: string\n moduleType: string\n moduleGroups: Array<string>\n resourcePot?: string\n sideEffects: boolean\n sourceMapChain: Array<string>\n external: boolean\n immutable: boolean\n}\nmodules(): Array<Module>\n"})}),"\n",(0,i.jsx)(r.p,{children:"Basic example:"}),"\n",(0,i.jsx)(r.pre,{children:(0,i.jsx)(r.code,{className:"language-javascript",children:'\nimport { Compiler } from "@farmfe/core";\nconst compiler = new Compiler(config);\nconst result = compiler.modules();\n'})})]})}function h(e={}){const{wrapper:r}={...(0,s.R)(),...e.components};return r?(0,i.jsx)(r,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},37620:(e,r,n)=>{n.d(r,{k:()=>f});var i=n(48318);const s=(0,i.createContext)({tabData:{},setTabData:()=>{}}),a={container:"container__nVC","tab-list":"tab-list_aJ1t",tab:"tab_J4Y8",selected:"selected_erAK","no-scrollbar":"no-scrollbar_vtMC"};var c=n(49214);const l=e=>function(e){return!(!e||"object"!=typeof e||!("label"in e))}(e)?e.label||e.value:e,t=(0,i.forwardRef)(((e,r)=>{const{values:n,defaultValue:t,onChange:o,children:d,groupId:p,tabPosition:h="left",tabContainerClassName:m}=e,u=i.Children.toArray(d).filter((e=>!("string"==typeof e&&""===e.trim())));let x=n||[];0===x.length&&(x=i.Children.map(u,(e=>(0,i.isValidElement)(e)?{label:e.props?.label,value:e.props?.value||e.props?.label}:{label:void 0,value:void 0})));const{tabData:v,setTabData:j}=(0,i.useContext)(s),[f,g]=(0,i.useState)((()=>void 0===t?0:x.findIndex((e=>"string"==typeof e?e===t:!(!e||"object"!=typeof e||!("value"in e))&&e.value===t)))),[y,w]=function(e,r){void 0===r&&(r=null);const[n,s]=(0,i.useState)((()=>"undefined"==typeof window?r:localStorage.getItem(e)??r)),a=(0,i.useCallback)((r=>{s((n=>{const i="function"==typeof r?r(n):r;return null==i?localStorage.removeItem(e):localStorage.setItem(e,i),i}))}),[e]);return(0,i.useEffect)((()=>{const n=n=>{n.key===e&&s(localStorage.getItem(e)??r)};return window.addEventListener("storage",n),()=>{window.removeEventListener("storage",n)}}),[e,r]),[n,a]}(`tabs.${p}`,f),b=(0,i.useMemo)((()=>p?void 0!==v[p]?v[p]:Number.parseInt(y):f),[v[p]]);(0,i.useEffect)((()=>{if(p){const e=Number.parseInt(y);b!==e&&j({...v,[p]:e})}}),[y]),(0,i.useEffect)((()=>{N(p?b:f)}),[p,b,f]);const[C,N]=(0,i.useState)(p?b:f);return(0,c.jsxs)("div",{className:a.container,ref:r,children:[(0,c.jsx)("div",{className:m,children:x.length?(0,c.jsx)("div",{className:`${a["tab-list"]} ${a["no-scrollbar"]}`,style:{display:"flex",justifyContent:"center"===h?"center":"flex-start"},children:x.map(((e,r)=>(0,c.jsx)("div",{className:`${a.tab} ${C===r?a.selected:a["not-selected"]}`,onClick:()=>{const e=r;o?.(e),N(e),p?(j({...v,[p]:e}),w(e)):g(e)},children:l(e)},r)))}):null}),(0,c.jsx)("div",{children:i.Children.toArray(u)[C]})]})}));function o(e){let{children:r,...n}=e;return(0,c.jsx)("div",{...n,className:"rounded-md",children:r})}function d(e){return(0,c.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 256 256",...e,children:[(0,c.jsx)("path",{fill:"#C12127",d:"M0 256V0h256v256z"}),(0,c.jsx)("path",{fill:"#FFF",d:"M48 48h160v160h-32V80h-48v128H48z"})]})}function p(e){return(0,c.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 128 128",...e,children:(0,c.jsxs)("g",{fill:"#2c8ebb",children:[(0,c.jsx)("path",{d:"M99.24 80.71C94.9 80.76 91.1 83 87.89 85c-6 3.71-9 3.47-9 3.47l-.1-.17c-.41-.67 1.92-6.68-.69-13.84c-2.82-7.83-7.3-9.72-6.94-10.32c1.53-2.59 5.36-6.7 6.89-14.36c.91-4.64.67-12.28-1.39-16.28c-.38-.74-3.78 1.24-3.78 1.24s-3.18-7.09-4.07-7.66c-2.87-1.84-6 7.61-6 7.61a14 14 0 0 0-11.71 4.5a9.64 9.64 0 0 1-3.85 2.27c-.41.14-.91.12-2.15 3.47c-1.9 5.07 3.24 10.81 3.24 10.81s-6.13 4.33-8.4 9.72a24.78 24.78 0 0 0-1.75 11.68s-4.36 3.78-4.64 7.68a12.87 12.87 0 0 0 1.77 7.83a1.94 1.94 0 0 0 2.63.91s-2.9 3.38-.19 4.81c2.47 1.29 6.63 2 8.83-.19c1.6-1.6 1.92-5.17 2.51-6.63c.14-.34.62.57 1.08 1a10 10 0 0 0 1.36 1s-3.9 1.68-2.3 5.51c.53 1.27 2.42 2.08 5.51 2.06c1.15 0 13.76-.72 17.12-1.53a4.33 4.33 0 0 0 2.61-1.46a63 63 0 0 0 15.49-7c4.74-3.09 6.68-3.93 10.51-4.84c3.16-.75 2.95-5.65-1.24-5.58z"}),(0,c.jsx)("path",{d:"M64 2a62 62 0 1 0 62 62A62 62 0 0 0 64 2zm37.3 87.83c-3.35.81-4.91 1.44-9.41 4.36a67 67 0 0 1-15.56 7.18a8.71 8.71 0 0 1-3.64 1.77c-3.81.93-16.88 1.63-17.91 1.63h-.24c-4 0-6.27-1.24-7.49-2.54c-3.4 1.7-7.8 1-11-.69a5.55 5.55 0 0 1-3-3.9a6 6 0 0 1 0-2.06a6.66 6.66 0 0 1-.79-1A16.38 16.38 0 0 1 3
10 84.52c.29-3.73 2.87-7.06 4.55-8.83A28.56 28.56 0 0 1 36.61 64a26.82 26.82 0 0 1 6.82-9c-1.65-2.78-3.33-7.06-1.7-11.42c1.17-3.11 2.13-4.84 4.24-5.58a6.84 6.84 0 0 0 2.51-1.34A17.65 17.65 0 0 1 60.34 31c.19-.48.41-1 .65-1.46c1.6-3.4 3.3-5.31 5.29-6a4.88 4.88 0 0 1 4.4.5c.65.43 1.48 1 3.9 6a4.69 4.69 0 0 1 2.85-.1a3.81 3.81 0 0 1 2.39 1.94c2.47 4.74 2.8 13.19 1.72 18.62a33.8 33.8 0 0 1-5.84 13.31a25.73 25.73 0 0 1 5.77 9.43a25.42 25.42 0 0 1 1.41 10.41A28.7 28.7 0 0 0 86 81.91c3.06-1.89 7.68-4.74 13.19-4.81a6.62 6.62 0 0 1 7 5.7a6.35 6.35 0 0 1-4.89 7.03z"})]})})}function h(e){return(0,c.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 128 128",...e,children:[(0,c.jsx)("path",{fill:"#f8ab00",d:"M0 .004V40h39.996V.004Zm43.996 0V40h40V.004Zm44.008 0V40H128V.004Zm0 43.996v39.996H128V44Z"}),(0,c.jsx)("path",{fill:"#4c4c4c",d:"M43.996 44v39.996h40V44ZM0 87.996v40h39.996v-40Zm43.996 0v40h40v-40Zm44.008 0v40H128v-40Z"})]})}function m(e){return(0,c.jsxs)("svg",{id:"Bun",width:"1.2em",height:"1.2em",viewBox:"0 0 80 70",...e,children:[(0,c.jsx)("path",{id:"Shadow",d:"M71.09,20.74c-.16-.17-.33-.34-.5-.5s-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5-.33-.34-.5-.5A26.46,26.46,0,0,1,75.5,35.7c0,16.57-16.82,30.05-37.5,30.05-11.58,0-21.94-4.23-28.83-10.86l.5.5.5.5.5.5.5.5.5.5.5.5.5.5C19.55,65.3,30.14,69.75,42,69.75c20.68,0,37.5-13.48,37.5-30C79.5,32.69,76.46,26,71.09,20.74Z"}),(0,c.jsxs)("g",{id:"Body",children:[(0,c.jsx)("path",{id:"Backgroun
1d",d:"M73,35.7c0,15.21-15.67,27.54-35,27.54S3,50.91,3,35.7C3,26.27,9,17.94,18.22,13S33.18,3,38,3s8.94,4.13,19.78,10C67,17.94,73,26.27,73,35.7Z",style:{fill:"#fbf0df"}}),(0,c.jsx)("path",{id:"Bottom_Shadow","data-name":"Bottom Shadow",d:"M73,35.7a21.67,21.67,0,0,0-.8-5.78c-2.73,33.3-43.35,34.9-59.32,24.94A40,40,0,0,0,38,63.24C57.3,63.24,73,50.89,73,35.7Z",style:{fill:"#f6dece"}}),(0,c.jsx)("path",{id:"Light_Shine","data-name":"Light Shine",d:"M24.53,11.17C29,8.49,34.94,3.46,40.78,3.45A9.29,9.29,0,0,0,38,3c-2.42,0-5,1.25-8.25,3.13-1.13.66-2.3,1.39-3.54,2.15-2.33,1.44-5,3.07-8,4.7C8.69,18.13,3,26.62,3,35.7c0,.4,0,.8,0,1.19C9.06,15.48,20.07,13.85,24.53,11.17Z",style:{fill:"#fffefc"}}),(0,c.jsx)("path",{id:"Top",d:"M35.12,5.53A16.41,16.41,0,0,1,29.49,18c-.28.25-.06.73.3.59,3.37-1.31,7.92-5.23,6-13.14C35.71,5,35.12,5.12,35.12,5.53Zm2.27,0A16.24,16.24,0,0,1,39,19c-.12.35.31.65.55.36C41.74,16.56,43.65,11,37.93,5,37.64,4.74,37.19,5.14,37.39,5.49Zm2.76-.17A16.42,16.42,0,0,1,47,17.12a.33.33,0,0,0,.65.11c.92-3.49.4-9.44-7.17-12.53C40.08,4.54,39.82,5.08,40.15,5.32ZM21.69,15.76a16.94,16.94,0,0,0,10.47-9c.18-.36.75-.22.66.18-1.73,8-7.52,9.67-11.12,9.45C21.32,16.4,21.33,15.87,21.69,15.76Z",style:{fill:"#ccbea7",fillRule:"evenodd"}}),(0,c.jsx)("path",{id:"Outline",d:"M38,65.75C17.32,65.75.5,52.27.5,35.7c0-10,6.18-19.33,16.53-24.92,3-1.6,5.57-3.21,7.86-4.62,1.26-.78,2.45-1.51,3.6-2.19C32,1.89,35,.5,38,.5s5.62,1.2,8.9,3.14c1,.57,2,1.19,3.07,1.87,2.49,1.54,5.3,3.28,9,5.27C69.32,16.37,75.5,25.69,75.5,35.7,75.5,52.27,58.68,65.75,38,65.75ZM38,3c-2.42,0-5,1.25-8.25,3.13-1.13.66-2.3,1.39-3.54,2.15-2.33,1.44-5,3.07-8,4.7C8.69,18.13,3,26.62,3,35.7,3,50.89,18.7,63.25,38,63.25S73,50.89,73,35.7C73,26.62,67.31,18.13,57.78,13,54,11,51.05,9.12,48.66,7.64c-1.09-.67-2.09-1.29-3-1.84C42.63,4,40.42,3,38,3Z"})]}),(0,c.jsxs)("g",{id:"Mouth",children:[(0,c.jsx)("g",{id:"Backgroun
1d-2","data-name":"Background",children:(0,c.jsx)("path",{d:"M45.05,43a8.93,8.93,0,0,1-2.92,4.71,6.81,6.81,0,0,1-4,1.88A6.84,6.84,0,0,1,34,47.71,8.93,8.93,0,0,1,31.12,43a.72.72,0,0,1,.8-.81H44.26A.72.72,0,0,1,45.05,43Z",style:{fill:"#b71422"}})}),(0,c.jsxs)("g",{id:"Tongue",children:[(0,c.jsx)("path",{id:"Background-3","data-name":"Background",d:"M34,47.79a6.91,6.91,0,0,0,4.12,1.9,6.91,6.91,0,0,0,4.11-1.9,10.63,10.63,0,0,0,1-1.07,6.83,6.83,0,0,0-4.9-2.31,6.15,6.15,0,0,0-5,2.78C33.56,47.4,33.76,47.6,34,47.79Z",style:{fill:"#ff6164"}}),(0,c.jsx)("path",{id:"Outline-2","data-name":"Outline",d:"M34.16,47a5.36,5.36,0,0,1,4.19-2.08,6,6,0,0,1,4,1.69c.23-.25.45-.51.66-.77a7,7,0,0,0-4.71-1.93,6.36,6.36,0,0,0-4.89,2.36A9.53,9.53,0,0,0,34.16,47Z"})]}),(0,c.jsx)("path",{id:"Outline-3","data-name":"Outline",d:"M38.09,50.19a7.42,7.42,0,0,1-4.45-2,9.52,9.52,0,0,1-3.11-5.05,1.2,1.2,0,0,1,.26-1,1.41,1.41,0,0,1,1.13-.51H44.26a1.44,1.44,0,0,1,1.13.51,1.19,1.19,0,0,1,.25,1h0a9.52,9.52,0,0,1-3.11,5.05A7.42,7.42,0,0,1,38.09,50.19Zm-6.17-7.4c-.16,0-.2.07-.21.09a8.29,8.29,0,0,0,2.73,4.37A6.23,6.23,0,0,0,38.09,49a6.28,6.28,0,0,0,3.65-1.73,8.3,8.3,0,0,0,2.72-4.37.21.21,0,0,0-.2-.09Z"})]}),(0,c.jsxs)("g",{id:"Face",children:[(0,c.jsx)("ellipse",{id:"Right_Blush","data-name":"Right Blush",cx:"53.22",cy:"40.18",rx:"5.85",ry:"3.44",style:{fill:"#febbd0"}}),(0,c.jsx)("ellipse",{id:"Left_Bluch","data-name":"Left Bluch",cx:"22.95",cy:"40.18",rx:"5.85",ry:"3.44",style:{fill:"#febbd0"}}),(0,c.jsx)("path",{id:"Eyes",d:"M25.7,38.8a5.51,5.51,0,1,0-5.5-5.51A5.51,5.51,0,0,0,25.7,38.8Zm24.77,0A5.51,5.51,0,1,0,45,33.29,5.5,5.5,0,0,0,50.47,38.8Z",style:{fillRule:"evenodd"}}),(0,c.jsx)("path",{id:"Iris",d:"M24,33.64a2.07,2.07,0,1,0-2.06-2.07A2.07,2.07,0,0,0,24,33.64Zm24.77,0a2.07,2.07,0,1,0-2.06-2.07A2.07,2.07,0,0,0,48.75,33.64Z",style:{fill:"#fff",fillRule:"evenodd"}})]})]})}var u=n(3662),x=n(21970);function v(e){if(!e?.includes("install"))return e;const r=e.split(" ").filter((e=>!e.startsWith("-")&&!e.startsWith("--"))).join(" ");return"yarn install"===r||"bun install"===r?e:e.replace("install","add")}function j(e,r){let n=e;return["npm","yarn","pnpm","bun"].forEach((e=>{const i=new RegExp(`\\b${e}\\b`,"g");n=n.replace(i,r)})),n}function f(e){let r,{command:s,skip:a=!0,additionalTabs:l=[]}=e;const f={npm:(0,c.jsx)(d,{}),yarn:(0,c.jsx)(p,{}),pnpm:(0,c.jsx)(h,{}),bun:(0,c.jsx)(m,{})};if(l.forEach((e=>{f[e.tool]=e.icon})),"string"==typeof s?(r={npm:`npm ${s}`,yarn:`yarn ${s}`,pnpm:`pnpm ${s}`,bun:`bun ${s}`},l.forEach((e=>{r[e.tool]=a?j(s,e.tool):`${e.tool} ${s}`}))):r=s,r.yarn&&(r.yarn=v(r.yarn)),r.bun&&(r.bun=v(r.bun)),a){["npm","yarn","pnpm","bun"].forEach((e=>{r[e]=j(s,e)}))}const[g,y]=(0,i.useState)({}),{colorMode:w}=(0,x.G)(),b=(0,u.A)();return(0,i.useEffect)((()=>{!async function(){if(b){const{codeToHtml:e}=await Promise.all([n.e(2632),n.e(3605)]).then(n.bind(n,43605)),i={};for(const[n,s]of Object.entries(r))i[n]=await e(s,{lang:"bash",theme:"dark"===w?"vitesse-dark":"vitesse-light"});y(i)}}()}),[s,w,b]),(0,c.jsx)("div",{className:"border-solid my-4 rounded-md border-package",children:(0,c.jsx)(t,{groupId:"package.manager",values:Object.entries(r).map((e=>{let[r]=e;return(0,c.jsxs)("div",{className:"package-manager-tab",style:{display:"flex",alignItems:"center",padding:"2px 4px",borderRadius:"4px",transition:"background-color 0.3s ease"},children:[f[r],(0,c.jsx)("span",{className:"package-manager-name ",children:r})]},r)})),children:Object.entries(r).map((e=>{let[r,n]=e;return(0,c.jsx)(o,{children:(0,c.jsx)("div",{className:"codeBlock-tab shadow-md",dangerouslySetInnerHTML:{__html:g[r]||""}})},r)}))})})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.