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

embeddable-create-react-app

v1.0.4

Published

Embed create-react-app without doing any eject

Downloads

24

Readme

Quickly generate a webpack.config.js file to create an embeddable react widget or CDN friendly script build.min.js without ejecting create-react-app

npm downloads MIT License node-version version

The Problem

The current Create React App supports Code Splitting which means if you run npm build on your create react app you will find that it has generated a build folder with chunk files. Meaning there is no single bundle.min.js file for your app. Code Splitting is very good for performance but sometimes you just need a single bundle.min.js file for your small app so that you can easily embed or make a CDN version of your app. NB: I said small here because you don't want to make a single bundle.min.js file for a large app because it will create a huge size js file and can make your application slow.

The Solution

There are several solution for the end goal that is you want to use a single build script of one of your react app to another react app or you just want to use the build script to another website. If you Eject the create-react-app or use webpack to build your react app you can customize your webpack config to generate a build script. But in this section we will discuss about the ones whom are using create-react-app. Because, Most of us now a days simply just uses CRA to build any kind of react applications and also at the beginning stage of the application it's rarely a requirement that you may have to consider a single build script. The problem arise after you complete the app or you need to use an old app within the new app. So the situation is kind of like that is you don't want to eject your CRA app also you want a single build script. That's when you will need this solution embeddable-create-react-app. Basically what it does is, it generate a webpack.config.js within your app and then using CRA generated build folder it creates a build.min.js file for you.

Installation

npx embeddable-create-react-app

Usage

i) copy the below code and paste it into your package.json file's script section,

"web:build": "npm run build && npm run build:bundle",
"build:bundle": "webpack --config webpack.config.js",

ii) Run yarn web:build

That's it, check a dist folder has been created and the build.min.js file can be found into dist/build/static/js directory

NB: you may have to install uglifyjs-webpack-plugin and webpack-cli at step (ii) to avoid any module not found issue.

Inspiration

I originally created this to solve a problem, I was having to create a single build script using CRA for making a React Widget. I came to know about this solution while looking at one of the closed issue in CRA.

Other Solution

Whn you build the script using this solution if your app is big you will see the webpack warning that the js file crossed the standard file size limit (Of course it cross the size limit in most of the occasion because it's making an script using everything your vendor, app code, style etc into a single script). If you can afford a minimum js size file then it's ok otherwise, if your app is big any you are not allowed to have a big build script then you can follow the below solution,

Using CDN

This can be your best bet, basically what it will do is take your regular CRA build folder with code splitting chunks and host it for you. And from that hosts you can generate a cdn scripts. For Example: You can host a regular CRA app to AWS S3 and then you can create a CDN with CloudFront, you can check this article for further information, https://medium.com/ovrsea/deliver-your-react-app-in-milliseconds-with-cloudfront-fd3a2d038445

Using webpack config override

if you don't want to use a webpack.config.json in your CRA app. There are several library that lets you override the webpack configuration. you can use any of them to override the webpack configuration of our CRA and turn of the Code Splitting.

Using embeddable-react-widget

This a customized solution that uses webpack to build the react app for you. If you are not using CRA then embeddable-react-widget can be helpful for you.