- Separate entry points for node and browser.
- Specifying the browser field in package.json.
- Changes in the bundling process.
-
bundler - Module bundlers are tools frontend developers used to bundle JavaScript modules into a single JavaScript files that can be executed in the browser.
-
rollup - rollup.js is the module bundler that the JS SDK uses.
-
package.json fields -
-
main - The main field is a module ID that is the primary entry point to your program. Points to the CJS modules.
-
module - The module field is not an official npm feature but a common convention among bundlers to designate how to import an ESM version of a library. Points to the ES modules.
-
browser - If the module is meant to be used client-side, the browser field should be used instead of the main field.
-
-
TypeScript Source Code / \ Transpiles into JavaScript 'lib' folder / \ CJS module ES modules -
main -
lib/src/index.jsmodule -lib/es/src/index.js -
Rollup bundling output
graph-js-sdk.js- Bundled and minified file in IIFE format. This file can be directly used in the browser with a<script>tag.graph-es-sdk.js- Bundled file in ES format.
- Entry point for rollup -
lib/es/src/browser/index.js.
src/browser/index.jsdoes not exportRedirectHandlerandRedirectHandlerOptions. Redirection is handled by the browser.src/browser/index.jsexportssrc/browser/ImplicitMsalProvider.src/browser/ImplicitMsalProviderdoes not import or require 'msal' dependency. While,src/ImplicitMsalProviderimports or requires 'msal' in the implementation.- My assumption is that
src/browser/ImplicitMsalProvideris implemented specifically for the rollup process and to skip the rollup external dependency while usinggraph-js-sdk.jsin the browser.
Note - Browser applications using the ES modules from the npm package of the JS SDK refer to the module entry point - lib/es/src/index.js(not the browser entry point). Example - Graph Explorer.
- Use the browser field for the following -
- The Graph JS SDK currently has two entry files,
src/indexandsrc/browser/index. Use the browser field to indicate the browser entry point. Example -
"browser":
{ "lib/es/src/index.js": "lib/es/src/browser/index.js" }Currently, the main and "module field in the package.json. This will remain the same.
- Better way to handle environment specific implementation. For example, using the
browserfield as follows - "browser":
{
"stream": "stream-browserify",
"Feature-Node.js": "Feature-Browser.js"
}- Remove export of
src/browser/ImplicitMsalProviderfromsrc/browser/index.
- Till
ImplicitMsalProvideris maintained in the repo, maintain a separate entry point sayrollup-indexfor the rollup process which exportssrc/browser/indexandsrc/browser/ImplicitMsalProvider. - Continue rolling up the
src/browser/ImplicitMsalProvideras it is currently done and not introduce breaking changes here as it is going to be deprecated. - Remove the separate entry point once
ImplicitMsalProvideris removed and use the browser entry point for roll up thereafter. The goal is to maintain a consistent entry point or usage for browser applications using the JS SDK and the rollup/bundling process.
-
Bundle the authproviders separately as they are optional.
-
Stop bundling in ES format, that is remove
graph-es-sdk.jsas the ES modules are being shipped.