About the NPM packageThe NPM package for Office.js is a copy of what gets published to the official "evergreen" Office.js CDN, at . The Office.js CDN contains all currently available Office.js APIs at any moment in time. Each Office.js NPM package contains only Office.js APIs available on the Office.js CDN when the NPM package version was created.
Target scenariosThe NPM package for Office.js is intended as a way to obtain an offline copy (non-CDN) of the Office.js files, which can then be statically serve from your own site instead of using the CDN. This NPM package is provided for the following scenarios:
- Development of an Add-in behind a firewall, when accessing the Office.js CDN is not possible.
- Offline access to the Office.js APIs to facilitate offline debugging.
Best practicesBest practices for using the Office.js NPM package include:
- Refreshing the NPM package periodically to access new APIs and bug fixes.
- Using the NPM package according to the instructions. Do not import the NPM package as commonly done with other NPM packages.
- Do not use the NPM package in an Add-in intended for publication to AppSource. Add-ins that are published to AppSource must use the Office.js CDN.
SupportThe Office.js CDN is the official supported source for Office Add-ins. For the NPM package sourced through this repository, only the latest version of the package is supported. No support and no patches will be provided for previous versions of the package. The frequency of the updates to this repository and related NPM package to match the CDN version is not guaranteed. Outlook add-ins do not support hosting Office.js offline due to network access requirements for dependencies like the Microsoft Ajax library.
Install the NPM packageTo install "office-js" locally via the NPM package, run the following command:
npm install @microsoft/office-js --save
Our policy requires that developers always reference the latest version of Office.js library. This is to ensure that essential product updates are served quickly to the Office Add-ins by always referencing the latest release of the library for a given version, such as Generally Available (GA) version. Given that the latest Office.js release is backward-compatible with prior releases, it is safe to update to the most recent release of the library when one is available. Hence, only the latest version of Office.js NPM package is made available for installation.
Use the NPM packageInstalling the NPM package locally creates a set of static Office.js files in the
node_modules\@microsoft\office-js\distfolder of the directory where you ran the
npm installcommand. To use the NPM package, do the following:
- Either manually or as part of a build script (e.g.,
CopyWebpackPluginif you're using Webpack) have the files served from a destination of your choosing (e.g., from the
/assets/office-js/directory of your web server).
- Reference that location in a
<script>tag within the HTML file in your add-in project.
distfolder to the
assets/office-jsdirectory of your project, then you'd add the following
<script>tag to your HTML file: ```html ```
IntelliSense definitionsTypeScript definitions for Office.js are available.
- latest RELEASE version of Office.js:
@types/office-js> npm install @types/office-js --save-dev
- latest BETA version of Office.js:
@types/office-js-preview. > npm install @types/office-js-preview --save-dev
- any version:
dist/office.d.ts- In this repo: dist/office.d.ts
Use TypeScript definitions with the NPM packageIf you're using the Office.js NPM package for the firewall scenario and want a d.ts file that precisely matches the JS contents, use the d.ts file that is located within the
/dist/office.d.tsfolder of the NPM package. Achieve this by using a triple-slash reference.
- TIP: If you create a
references.tsfile at the root of the project, simply point the reference to
@types/office-jsand reference the Office.js CDN at .
office-vsdoc.jsis available alongside the
office.jsfile. As long as you have a
Scripts/_references.jsfile in your VS project, and as long as you substitute the existing triple-slash reference (
/// <reference path="https://.../office.js" />) with the new location (the
-vsdocpart gets substituted automatically, so use it just as you would in a
NPM Package VersionsOffice.js versioning is described in detail in . Importantly, there is a difference between what is in the JS files, versus what are the capabilities of a particular computer (i.e., older or slower-to-update versions of office). The NPM package and the repo branches assume the following structure. | GitHub branch name | NPM tag name | Description | | ------------------ |-------------- |-------------| |
latest| Identical to a previous release on
The latest released publicly-available APIs. | |
beta| Identical to a previous release on
Forthcoming APIs, not necessarily ready for public consumption that may change. Possibly available on Insider Fast (and maybe Insider Slow) builds. |
Code of ConductThis project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact email@example.com with any additional questions or comments.
Join the Microsoft 365 Developer ProgramGet a free sandbox, tools, and other resources you need to build solutions for the Microsoft 365 platform.
- Free developer sandbox Get a free, renewable 90-day Microsoft 365 E5 developer subscription.
- Sample data packs Automatically configure your sandbox by installing user data and content to help you build your solutions.
- Access to experts Access community events to learn from Microsoft 365 experts.
- Personalized recommendations Find developer resources quickly from your personalized dashboard.