mainehoogl.blogg.se

React dom 16 script tag unpkg reference
React dom 16 script tag unpkg reference





react dom 16 script tag unpkg reference

However, it is important to keep in mind that browser-cjs loads content synchronously, and in most cases a synchronous operation is not the desired or recommended way of loading this type of files (unless there is a specific reason for that, such as loading configuration files, or other special cases in which a synchronous operation is acceptable, or even preferred over an asynchronous operation). In addition to CommonJS modules, browser-cjs supports loading plain JSON files as well. (Please refer to the Limitations section). js, etc.), because without the extension, browser-cjs will assume that moduleName is a directory and it will try to load the /path/to/nodeModule/ file, where is the file main specified in the package.json (e.g.: main: "./index.js"). It is necessary to specify the extension of the file (. To use browser-cjs for loading and evaluating JS files in CommonJS module format, simply call the globally available function require with the name of the module file given as argument (as it's done in Node.js).įor instance, to load a module called moduleName.js: const moduleName = require( "/path/to/moduleName.js") Here is an example of such a module: module.exports = 'This is a string' Loading CommonJS modulesĬommonJS modules, or Javascript files in CommonJS module format, are files that expose JS functionality typically using the module.exports syntax.

react dom 16 script tag unpkg reference

Once the browser-cjs module loader is fully loaded, and its require utility function available in the browser's global scope, it is ready for loading content, which includes CommonJS modules and JSON data files.

React dom 16 script tag unpkg reference install#

To give browser-cjs a try install it with npm, using npm install browser-cjsĪnd load it in your page from its installation package using an HTML script tag, as shown in the following example: Īs an alternative, you may download a copy locally or reference it directly from unpkg: // For production In a case when the runtime environment already supports the require utility function (such as the ElectronJS environment, or the NWJS environment), browser-cjs will not override or replace the existing require function instead, it will reuse it as-is. In other words, it defines in the global scope of the browser a utility function called require, whose role is to synchronously load (without the need of a JS bundler, such as Webpack or Browserify) JS modules defined with to the CommonJS module syntax. A minimal CommonJS-like module loader for the browser environment.Īs a client-side CommonJS module loader, browser-cjs aims to implement a Node.js-like module loading utility in the browser environment.







React dom 16 script tag unpkg reference