Created
January 11, 2019 15:54
-
-
Save Gennnji/e8e85ce802a7c85ba6097cd449f2b6cb to your computer and use it in GitHub Desktop.
Install React from Scratch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, {Component} from 'react'; | |
| export default class App extends Component { | |
| render () { | |
| return <p>This is my new react app</p> | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title> Ideal React Seed </title> | |
| </head> | |
| <body> | |
| <div id="app"></div> | |
| <script type="text/javascript" src="/bundle.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| // main app | |
| import App from './containers/App'; | |
| ReactDOM.render(<App />, document.getElementById('app')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| npm install --save-dev babel-cli babel-core babel-loader babel-plugin-transform-object-rest-spread babel-preset-es2015 babel-preset-react babel-preset-stage-0 babel-register |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| npm install --save react react-dom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| npm install --save-dev style-loader css-loader less-loader | |
| npm install --save-dev less |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| npm install --save webpack webpack-dev-server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "babel": { | |
| "presets": [ | |
| "es2015", | |
| "react", | |
| "stage-0" | |
| ], | |
| "plugins": [ | |
| "transform-object-rest-spread" | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1", | |
| "dev": "./node_modules/.bin/webpack-dev-server --config ./webpack/webpack.dev.config.js" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir reactProject | |
| cd reactProject | |
| npm init // start a node project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir containers | |
| cd containers | |
| touch App.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir webpack | |
| cd webpack | |
| touch webpack.dev.config.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webpack = require('webpack'); | |
| var path = require('path'); | |
| var parentDir = path.join(__dirname, '../'); | |
| module.exports = { | |
| entry: [ | |
| path.join(parentDir, 'index.js') | |
| ], | |
| module: { | |
| loaders: [{ | |
| test: /\.(js|jsx)$/, | |
| exclude: /node_modules/, | |
| loader: 'babel-loader' | |
| },{ | |
| test: /\.less$/, | |
| loaders: ["style-loader", "css-loder", "less-loader"] | |
| } | |
| ] | |
| }, | |
| output: { | |
| path: parentDir + '/dist', | |
| filename: 'bundle.js' | |
| }, | |
| devServer: { | |
| contentBase: parentDir, | |
| historyApiFallback: true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm run dev