Skip to content

Instantly share code, notes, and snippets.

@vlucas
Created May 5, 2016 21:47
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 vlucas/f942f408209401e9d35711c10480b824 to your computer and use it in GitHub Desktop.
Save vlucas/f942f408209401e9d35711c10480b824 to your computer and use it in GitHub Desktop.
Shell function to setup a new React.js project
# Setup new React.js project
react_new() {
echo ">> Setting up NPM...";
npm init -y;
echo ">> Running NPM install...";
npm install --save react react-dom;
npm install --save-dev browserify babelify babel-preset-es2015 babel-preset-react fsmonitor;
echo ">> Setting up initial files...";
# index.html
echo '<html>
<head>
<title>React.js Starter Project</title>
</head>
<body>
<p>Example React.js starter project</p>
<div id="content"></div>
<script src="dist/bundle.js"></script>
</body>
</html>
' >> index.html;
# Setup directories
mkdir dist src src/components;
# src/components/App.js
echo "'use strict';
const React = require('react');
const App = React.createClass({
render() {
return (
<p>Hello React.js!</p>
);
}
});
module.exports = App;" >> src/components/App.js;
touch src/index.js;
echo "'use strict';\nconst React = require('react');\nconst ReactDOM = require('react-dom');\nconst App = require('components/App');\n\nReactDOM.render(<App />, document.getElementById('content'));" >> src/index.js;
echo "Add these NPM 'script' tasks:\n";
echo ' "build": "NODE_PATH=./src ./node_modules/browserify/bin/cmd.js src/index.js -o dist/bundle.js -t [ babelify --presets [ es2015 react ] ]"';
echo ' "watch": "./node_modules/fsmonitor/bin/fsmonitor.js -s -d src npm run build"';
echo "\n\n";
}
@cristea2017
Copy link

Exactly what i searched ) thx ;)

@vlucas
Copy link
Author

vlucas commented Jan 10, 2020

This is old - this pre-dates create-react-app, which is what I would use today.

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