{"kind":"AgentDefinition","metadata":{"namespace":"community","name":"pcf-dependent-libraries","version":"0.1.0"},"spec":{"agents_md":"---\ndescription: 'Using dependent libraries in PCF components'\napplyTo: '**/*.{ts,tsx,js,json,xml,pcfproj,csproj}'\n---\n\n# Dependent Libraries (Preview)\n\n[This topic is pre-release documentation and is subject to change.]\n\nWith model-driven apps, you can reuse a prebuilt library contained in another component that is loaded as a dependency to more than one component.\n\nHaving copies of a prebuilt library in multiple controls is undesirable. Reusing existing libraries improves performance, especially when the library is large, by reducing the load time for all components that use the library. Library reuse also helps reduce the maintenance overhead in build processes.\n\n## Before and After\n\n**Before**: Custom library files contained in each PCF component\n![Diagram showing custom library files contained in each pcf component](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/media/dependent-library-before-example.png)\n\n**After**: Components calling a shared function from a Library Control\n![Diagram showing components calling a shared function from a Library Control](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/media/dependent-library-after-example.png)\n\n## Implementation Steps\n\nTo use dependent libraries, you need to:\n\n1. Create a **Library component** that contains the library. This component can provide some functionality or only be a container for the library.\n2. Configure another component to depend on the library loaded by the library component.\n\nBy default, the library loads when the dependent component loads, but you can configure it to load on demand.\n\nThis way you can independently maintain the library in the Library Control and the dependent controls don't need to have a copy of the library bundled with them.\n\n## How It Works\n\nYou need to add configuration data to your component project so that the build process deploys your libraries the way you want. Set this configuration data by adding or editing the following files:\n\n- **featureconfig.json**\n- **webpack.config.js**\n- Edit the manifest schema to **Register dependencies**\n\n### featureconfig.json\n\nAdd this file to override the default feature flags for a component without modifying the files generated in the `node_modules` folder.\n\n**Feature Flags:**\n\n| Flag | Description |\n|------|-------------|\n| `pcfResourceDependency` | Enables the component to use a library resource. |\n| `pcfAllowCustomWebpack` | Enables the component to use a custom web pack. This feature must be enabled for components that define a library resource. |\n\nBy default, these values are `off`. Set them to `on` to override the default.\n\n**Example 1:**\n```json\n{ \n  \"pcfAllowCustomWebpack\": \"on\" \n} \n```\n\n**Example 2:**\n```json\n{ \n   \"pcfResourceDependency\": \"on\",\n   \"pcfAllowCustomWebpack\": \"off\" \n} \n```\n\n### webpack.config.js\n\nThe build process for components uses [Webpack](https://webpack.js.org/) to bundle the code and dependencies into a deployable asset. To exclude your libraries from this bundling, add a `webpack.config.js` file to the project root folder that specifies the alias of the library as `externals`. [Learn more about the Webpack externals configuration option](https://webpack.js.org/configuration/externals/)\n\nThis file might look like the following when the library alias is `myLib`:\n\n```javascript\n/* eslint-disable */ \n\"use strict\"; \n\nmodule.exports = { \n  externals: { \n    \"myLib\": \"myLib\" \n  }, \n}  \n```\n\n### Register Dependencies\n\nUse the [dependency element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/dependency) within [resources](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/resources) of the manifest schema.\n\n```xml\n\u003cresources\u003e\n  \u003cdependency\n    type=\"control\"\n    name=\"samples_SampleNS.SampleStubLibraryPCF\"\n    order=\"1\"\n  /\u003e\n  \u003ccode path=\"index.ts\" order=\"2\" /\u003e\n\u003c/resources\u003e\n```\n\n### Dependency as On-Demand Load of a Component\n\nRather than loading the dependent library when a component loads, you can load the dependent library on demand. Loading on demand provides the flexibility for more complex controls to only load dependencies when they're required, especially if the dependent libraries are large.\n\n![Diagram showing the use of a function from a library where the library is loaded on demand](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/media/dependent-library-on-demand-load.png)\n\nTo enable on demand loading, you need to:\n\n**Step 1**: Add these [platform-action element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/platform-action), [feature-usage element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/feature-usage), and [uses-feature element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/uses-feature) child elements to the [control element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/control):\n\n```xml\n\u003cplatform-action action-type=\"afterPageLoad\" /\u003e\n\u003cfeature-usage\u003e\n   \u003cuses-feature name=\"Utility\"\n      required=\"true\" /\u003e\n\u003c/feature-usage\u003e\n```\n\n**Step 2**: Set the `load-type` attribute of the [dependency element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/dependency) to `onDemand`.\n\n```xml\n\u003cdependency type=\"control\"\n      name=\"samples_SampleNamespace.StubLibrary\"\n      load-type=\"onDemand\" /\u003e\n```\n\n## Next Steps\n\nTry a tutorial that walks you through creating a dependent library:\n\n[Tutorial: Use dependent libraries in a component](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/tutorial-use-dependent-libraries)\n","description":"Using dependent libraries in PCF components","import":{"commit_sha":"541b7819d8c3545c6df122491af4fa1eae415779","imported_at":"2026-05-18T20:05:35Z","license_text":"MIT License\n\nCopyright GitHub, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","owner":"github","repo":"github/awesome-copilot","source_url":"https://github.com/github/awesome-copilot/blob/541b7819d8c3545c6df122491af4fa1eae415779/instructions/pcf-dependent-libraries.instructions.md"},"manifest":{}},"content_hash":[89,207,42,134,189,162,140,22,69,123,40,168,37,15,148,245,130,200,214,237,2,134,129,59,59,241,123,165,65,47,142,238],"trust_level":"unsigned","yanked":false}
