SharePoint Framework build tool that automatically re-writes URL's in the manifest.
JavaScript TypeScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


SharePoint Framework build tool that automatically re-writes URL's in the manifest.



For ISV's and SI's the SharePoint Framework has a huge disadvantage in how configuration is handled. It contains hardcoded references to external URL's and hosting location of the bundled SharePoint Framework files. If you are re-using a SharePoint Framework solution for multiple tenants/clients/environments you need to manually modify the configuration files between each build. The spfx-build-url-rewrite allows you to rewrite these URL's at build time to build packages targeted to specific tenants/URLs without modifying the SharePoint Framework configuration files.


You add the package to your SPFx solution as follows:

npm install spfx-build-url-rewrite --save

In order to use the package you need to modify the gulpfile.js file as follows. Before the line containing build.initialize(gulp); insert the following lines:

const rewrite = require('spfx-build-url-rewrite');


To be able to rewrite external URLs (stored in ./config/config.json) and the CDN URL (stored in ./config/write-manifest.json) you must adress the URLs using the following URL

Example of config.json:

 "externals": {
    "sp-init": {
      "path": "",
      "globalName": "$_global_init"
    "microsoft-ajax": {
      "path": "",
      "globalName": "Sys",
      "globalDependencies": [

Example of write-manifest.json:

  "cdnBasePath": ""

How to rewrite during the build

You have two options to do the re-write during your build; either using the command line or using environment variables

Rewrite using the command line

In order to re-write using the command line use the --target-cdn argument like this:

gulp build --target-cdn

Rewrite using environment variables

To avoid specifying the command line argument you can use the TargetCdn (process.enc.TargetCdn) environment variable. To use argument variables in the command line you can create a file called .env in the root folder and add content as follows: