npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-ecmascript

v1.4.4

Published

A script which transform React and ReactDOM into native Ecmascript modules to be used in browsers which support Ecmascript modules and module loading

Downloads

40

Readme

react-ecmascript

ECMAScript module versions of

  • react.production.min.js
  • react-dom.production.min.js
  • react.development.js
  • react-dom.development.js

with the right exports and imports to use them directly in browsers which support ECMAScript modules and module loading.

react and react-dom version: 16.6.3

usage

pkg.module

The module property in package.json only supports one file, and this creates four modules to use. Therefor the pkg.module isn't used and you need to copy the files yourself. Or generate them before you use them in development or during your build step.

during development import them directly from unpkg.com

import React from 'https://unpkg.com/[email protected]/react.development.mjs';
import ReactDOM from 'https://unpkg.com/[email protected]/react-dom.development.mjs';

copy paste

In the root of this repo are the four script files.

  • react.development.mjs
  • react-dom.development.mjs
  • react.production.min.mjs
  • react-dom.production.min.mjs

You can copy paste the relevant files and upload them to wherever you want. They should work right away because the module specifier is a relative one.

As an NPM module in node

Install

npm i react-ecmascript

Than generate the sources in Node

const reactEcmascript = require('react-ecmascript');

reactEcmascript('someUrl') // optional uri as argument, pass in the folder. the correct filename will get appended
  .then(sources => {
    console.log(sources);
    /*
    {
      'react.production.min.mjs': 'content as string',
      'react-dom.production.min.mjs': 'content as string',
      'react.development.mjs': 'content as string',
      'react-dom.development.mjs': 'content as string'
    }
    */

    // do something with these sources, like saving them to disk to use them in your project
  });

Replacing the import uri for react automatically

The optional argument that can be passed to the function exported by the react-ecmascript module is the directory where these files will be made available to be used in a browser. The relevant filename to import will get appended automatically (production.min or development). In most cases this will not be needed though.

Usage with Rollup

The files generated by this script can be used directly in Rollup. To use these files through Rollup you will need to add the correct settings to the Rollup config.

Add react and react-dom to the output.paths object so Rollup knows with what to replace the module specifier in the files that import react and react-dom:

{
  react: urlWhereTheReactFileWillBeDeployed,
  'react-dom': urlWhereTheReactDOMFileWillBeDeployed
}

and also flag them as being external in the external array to prevent unfound modules messages:

[
  'react',
  'react-dom',
  `${directoryWhereTheFilesWillBeDeployed}react.development.mjs`,
  `${directoryWhereTheFilesWillBeDeployed}react-dom.development.mjs`,
  `${directoryWhereTheFilesWillBeDeployed}react.production.min.mjs`,
  `${directoryWhereTheFilesWillBeDeployed}react-dom.production.min.mjs`
]

You can also reference the files directly from the node_modules directory in Rollup if you're using the 'rollup-plugin-node-resolve' plugin.

Notice

When react and react-dom have a module entry in their package.json and they will have formalized the top-level ES exports this module will be deprecated. Untill then this is the next best thing if you want to use react and react-dom as ECMAScript modules in a browser.