Skip to content

Instantly share code, notes, and snippets.

@kamikat
Last active October 11, 2019 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamikat/fd3a1def9a4f32abfb9806d9106a7e7b to your computer and use it in GitHub Desktop.
Save kamikat/fd3a1def9a4f32abfb9806d9106a7e7b to your computer and use it in GitHub Desktop.
Convert CRA project to re-distributable component package.
diff --git a/.gitignore b/.gitignore
index 4d29575..3835823 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+
+/dist
+/yarn.lock
diff --git a/package.json b/package.json
index 1da6187..be3be0b 100644
--- a/package.json
+++ b/package.json
@@ -3,16 +3,40 @@
"version": "0.1.0",
"private": true,
"dependencies": {
+ "@babel/cli": "^7.6.2",
+ "@babel/core": "^7.6.2",
+ "@babel/preset-env": "^7.6.2",
+ "@babel/preset-react": "^7.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0",
+ "react-dom": "^16.8.0"
+ },
+ "devDependencies": {
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
- "build": "react-scripts build",
+ "prepublish": "npm run build",
+ "postinstall": "test -d src && npm run build",
+ "build": "rm -rf dist && NODE_ENV=production babel src/lib --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,__snapshots__",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
+ "main": "dist/index.js",
+ "module": "dist/index.js",
+ "files": [
+ "dist/*",
+ "README.md"
+ ],
+ "babel": {
+ "presets": [
+ "@babel/env",
+ "@babel/react"
+ ]
+ },
"eslintConfig": {
"extends": "react-app"
},
@kamikat
Copy link
Author

kamikat commented Oct 8, 2019

Patch a React App project to be a re-distributable React Component project.

patch -p1 < react-component-package.patch 
git rm --cached yarn.lock
yarn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment