├── project-board-react ├── src │ ├── App.css │ ├── actions │ │ ├── types.js │ │ └── projectTaskActions.js │ ├── App.test.js │ ├── reducers │ │ ├── index.js │ │ ├── errorsReducer.js │ │ └── projectTaskReducer.js │ ├── index.css │ ├── index.js │ ├── components │ │ ├── Navbar.js │ │ ├── ProjectTask │ │ │ ├── ProjectTaskItem.js │ │ │ ├── AddProjectTask.js │ │ │ └── UpdateProjectTask.js │ │ └── ProjectBoard.js │ ├── store.js │ ├── App.js │ └── serviceWorker.js ├── public │ ├── favicon.ico │ ├── manifest.json │ └── index.html ├── .gitignore ├── package.json └── README.md ├── projectboard ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── io │ │ │ └── agileintelligence │ │ │ └── projectboard │ │ │ ├── ProjectboardApplication.java │ │ │ ├── repository │ │ │ └── ProjectTaskRepository.java │ │ │ ├── service │ │ │ └── ProjectTaskService.java │ │ │ ├── domain │ │ │ └── ProjectTask.java │ │ │ └── web │ │ │ └── ProjectTaskController.java │ └── test │ │ └── java │ │ └── io │ │ └── agileintelligence │ │ └── projectboard │ │ └── ProjectboardApplicationTests.java ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.properties │ │ └── maven-wrapper.jar ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw ├── .idea ├── modules.xml ├── misc.xml ├── ProjectBoardCourse.iml ├── inspectionProfiles │ └── Project_Default.xml ├── libraries │ └── antlr_2_7_7.xml └── workspace.xml └── design ├── ProjectTaskForm.html └── ProjectBoard.html /project-board-react/src/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /projectboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project-board-react/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AgileIntYoutube/FullStackProjectSpringReactRedux/HEAD/project-board-react/public/favicon.ico -------------------------------------------------------------------------------- /projectboard/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /projectboard/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AgileIntYoutube/FullStackProjectSpringReactRedux/HEAD/projectboard/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /project-board-react/src/actions/types.js: -------------------------------------------------------------------------------- 1 | export const GET_ERRORS = "GET_ERRORS"; 2 | export const GET_PROJECT_TASKS = "GET_PROJECT_TASKS"; 3 | export const GET_PROJECT_TASK = "GET_PROJECT_TASK"; 4 | export const DELETE_PROJECT_TASK = "DELETE_PROJECT_TASK"; 5 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /project-board-react/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /project-board-react/src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from "redux"; 2 | import errorsReducer from "./errorsReducer"; 3 | import projectTaskReducer from "./projectTaskReducer"; 4 | 5 | export default combineReducers({ 6 | // 7 | errors: errorsReducer, 8 | project_task: projectTaskReducer 9 | }); 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /project-board-react/src/reducers/errorsReducer.js: -------------------------------------------------------------------------------- 1 | import { GET_ERRORS } from "../actions/types"; 2 | 3 | const initialState = {}; 4 | 5 | export default function(state = initialState, action) { 6 | switch (action.type) { 7 | case GET_ERRORS: 8 | return action.payload; 9 | 10 | default: 11 | return state; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projectboard/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /project-board-react/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /project-board-react/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /project-board-react/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /projectboard/src/main/java/io/agileintelligence/projectboard/ProjectboardApplication.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProjectboardApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProjectboardApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /projectboard/src/main/java/io/agileintelligence/projectboard/repository/ProjectTaskRepository.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard.repository; 2 | 3 | import io.agileintelligence.projectboard.domain.ProjectTask; 4 | import org.springframework.data.repository.CrudRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface ProjectTaskRepository extends CrudRepository { 9 | 10 | ProjectTask getById(Long id); 11 | } 12 | -------------------------------------------------------------------------------- /projectboard/src/test/java/io/agileintelligence/projectboard/ProjectboardApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProjectboardApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /project-board-react/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /.idea/ProjectBoardCourse.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /project-board-react/src/components/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default function Navbar() { 4 | return ( 5 | 6 | 7 | 8 | Project Task Tool 9 | 10 | 16 | 17 | 18 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /project-board-react/src/store.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware, compose } from "redux"; 2 | import thunk from "redux-thunk"; 3 | import rootReducer from "./reducers"; 4 | 5 | const initialState = {}; 6 | const middleware = [thunk]; 7 | 8 | const ReactReduxDevTools = 9 | window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(); 10 | let store; 11 | 12 | if (window.navigator.userAgent.includes("Chrome") && ReactReduxDevTools) { 13 | store = createStore( 14 | rootReducer, 15 | initialState, 16 | compose( 17 | applyMiddleware(...middleware), 18 | ReactReduxDevTools 19 | ) 20 | ); 21 | } else { 22 | store = createStore( 23 | rootReducer, 24 | initialState, 25 | compose(applyMiddleware(...middleware)) 26 | ); 27 | } 28 | 29 | export default store; 30 | -------------------------------------------------------------------------------- /project-board-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "project-board-react", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "axios": "^0.18.0", 7 | "bootstrap": "^4.1.3", 8 | "classnames": "^2.2.6", 9 | "react": "^16.5.2", 10 | "react-dom": "^16.5.2", 11 | "react-redux": "^5.1.0", 12 | "react-router-dom": "^4.3.1", 13 | "react-scripts": "2.0.5", 14 | "redux": "^4.0.1", 15 | "redux-thunk": "^2.3.0" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": "react-app" 25 | }, 26 | "browserslist": [ 27 | ">0.2%", 28 | "not dead", 29 | "not ie <= 11", 30 | "not op_mini all" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /project-board-react/src/reducers/projectTaskReducer.js: -------------------------------------------------------------------------------- 1 | import { 2 | GET_PROJECT_TASKS, 3 | DELETE_PROJECT_TASK, 4 | GET_PROJECT_TASK 5 | } from "../actions/types"; 6 | 7 | const initialState = { 8 | project_tasks: [], 9 | project_task: {} 10 | }; 11 | 12 | export default function(state = initialState, action) { 13 | switch (action.type) { 14 | case GET_PROJECT_TASKS: 15 | return { 16 | ...state, 17 | project_tasks: action.payload 18 | }; 19 | 20 | case GET_PROJECT_TASK: 21 | return { 22 | ...state, 23 | project_task: action.payload 24 | }; 25 | 26 | case DELETE_PROJECT_TASK: 27 | return { 28 | ...state, 29 | project_tasks: state.project_tasks.filter( 30 | project_task => project_task.id !== action.payload 31 | ) 32 | }; 33 | default: 34 | return state; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /project-board-react/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "./App.css"; 3 | import "bootstrap/dist/css/bootstrap.min.css"; 4 | import Navbar from "./components/Navbar"; 5 | import ProjectBoard from "./components/ProjectBoard"; 6 | import { BrowserRouter as Router, Route } from "react-router-dom"; 7 | import AddProjectTask from "./components/ProjectTask/AddProjectTask"; 8 | import { Provider } from "react-redux"; 9 | import store from "./store"; 10 | import UpdateProjectTask from "./components/ProjectTask/UpdateProjectTask"; 11 | 12 | class App extends Component { 13 | render() { 14 | return ( 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | ); 31 | } 32 | } 33 | 34 | export default App; 35 | -------------------------------------------------------------------------------- /projectboard/src/main/java/io/agileintelligence/projectboard/service/ProjectTaskService.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard.service; 2 | 3 | import io.agileintelligence.projectboard.domain.ProjectTask; 4 | import io.agileintelligence.projectboard.repository.ProjectTaskRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class ProjectTaskService { 10 | 11 | @Autowired 12 | private ProjectTaskRepository projectTaskRepository; 13 | 14 | public ProjectTask saveOrUpdateProjectTask(ProjectTask projectTask){ 15 | 16 | if(projectTask.getStatus()==null || projectTask.getStatus()==""){ 17 | projectTask.setStatus("TO_DO"); 18 | } 19 | 20 | return projectTaskRepository.save(projectTask); 21 | } 22 | 23 | 24 | public Iterable findAll(){ 25 | return projectTaskRepository.findAll(); 26 | } 27 | 28 | public ProjectTask findById(Long id){ 29 | return projectTaskRepository.getById(id); 30 | } 31 | 32 | public void delete(Long id){ 33 | ProjectTask projectTask = findById(id); 34 | projectTaskRepository.delete(projectTask); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.idea/libraries/antlr_2_7_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /projectboard/src/main/java/io/agileintelligence/projectboard/domain/ProjectTask.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.validation.constraints.NotBlank; 8 | 9 | @Entity 10 | public class ProjectTask { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | private Long id; 15 | 16 | @NotBlank(message = "Summary cannot be blank") 17 | private String summary; 18 | private String acceptanceCriteria; 19 | private String status; 20 | 21 | public ProjectTask() { 22 | } 23 | 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getSummary() { 34 | return summary; 35 | } 36 | 37 | public void setSummary(String summary) { 38 | this.summary = summary; 39 | } 40 | 41 | public String getAcceptanceCriteria() { 42 | return acceptanceCriteria; 43 | } 44 | 45 | public void setAcceptanceCriteria(String acceptanceCriteria) { 46 | this.acceptanceCriteria = acceptanceCriteria; 47 | } 48 | 49 | public String getStatus() { 50 | return status; 51 | } 52 | 53 | public void setStatus(String status) { 54 | this.status = status; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /project-board-react/src/components/ProjectTask/ProjectTaskItem.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | import PropTypes from "prop-types"; 4 | import { connect } from "react-redux"; 5 | import { deleteProjectTask } from "../../actions/projectTaskActions"; 6 | 7 | class ProjectTaskItem extends Component { 8 | onDeleteClick(pt_id) { 9 | this.props.deleteProjectTask(pt_id); 10 | } 11 | 12 | render() { 13 | const { project_task } = this.props; 14 | return ( 15 | 16 | ID: {project_task.id} 17 | 18 | {project_task.summary} 19 | 20 | {project_task.acceptanceCriteria} 21 | 22 | 26 | View / Update 27 | 28 | 29 | 33 | Delete 34 | 35 | 36 | 37 | ); 38 | } 39 | } 40 | 41 | ProjectTaskItem.propTypes = { 42 | deleteProjectTask: PropTypes.func.isRequired 43 | }; 44 | 45 | export default connect( 46 | null, 47 | { deleteProjectTask } 48 | )(ProjectTaskItem); 49 | -------------------------------------------------------------------------------- /project-board-react/src/actions/projectTaskActions.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { 3 | GET_ERRORS, 4 | GET_PROJECT_TASKS, 5 | DELETE_PROJECT_TASK, 6 | GET_PROJECT_TASK 7 | } from "./types"; 8 | 9 | export const addProjectTask = (project_task, history) => async dispatch => { 10 | try { 11 | await axios.post("http://localhost:8080/api/board", project_task); 12 | history.push("/"); 13 | dispatch({ 14 | type: GET_ERRORS, 15 | payload: {} 16 | }); 17 | } catch (error) { 18 | dispatch({ 19 | type: GET_ERRORS, 20 | payload: error.response.data 21 | }); 22 | } 23 | }; 24 | 25 | export const getBacklog = () => async dispatch => { 26 | const res = await axios.get("http://localhost:8080/api/board/all"); 27 | dispatch({ 28 | type: GET_PROJECT_TASKS, 29 | payload: res.data 30 | }); 31 | }; 32 | 33 | export const deleteProjectTask = pt_id => async dispatch => { 34 | if ( 35 | window.confirm( 36 | `You are deleting project task ${pt_id}, this action cannot be undone` 37 | ) 38 | ) { 39 | await axios.delete(`http://localhost:8080/api/board/${pt_id}`); 40 | dispatch({ 41 | type: DELETE_PROJECT_TASK, 42 | payload: pt_id 43 | }); 44 | } 45 | }; 46 | 47 | export const getProjectTask = (pt_id, history) => async dispatch => { 48 | try { 49 | const res = await axios.get(`http://localhost:8080/api/board/${pt_id}`); 50 | dispatch({ 51 | type: GET_PROJECT_TASK, 52 | payload: res.data 53 | }); 54 | } catch (error) { 55 | history.push("/"); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /project-board-react/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 23 | 25 | PROJECT BOARD!!! App 26 | 27 | 28 | 29 | 30 | You need to enable JavaScript to run this app. 31 | 32 | 33 | 34 | 35 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /projectboard/src/main/java/io/agileintelligence/projectboard/web/ProjectTaskController.java: -------------------------------------------------------------------------------- 1 | package io.agileintelligence.projectboard.web; 2 | 3 | 4 | import io.agileintelligence.projectboard.domain.ProjectTask; 5 | import io.agileintelligence.projectboard.service.ProjectTaskService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.validation.BindingResult; 10 | import org.springframework.validation.FieldError; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.validation.Valid; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @RestController 18 | @RequestMapping("/api/board") 19 | @CrossOrigin 20 | public class ProjectTaskController { 21 | 22 | @Autowired 23 | private ProjectTaskService projectTaskService; 24 | 25 | @PostMapping("") 26 | public ResponseEntity> addPTToBoard(@Valid @RequestBody ProjectTask projectTask, BindingResult result){ 27 | 28 | if(result.hasErrors()){ 29 | Map errorMap = new HashMap<>(); 30 | 31 | for(FieldError error: result.getFieldErrors()){ 32 | errorMap.put(error.getField(), error.getDefaultMessage()); 33 | } 34 | return new ResponseEntity>(errorMap, HttpStatus.BAD_REQUEST); 35 | } 36 | 37 | ProjectTask newPT = projectTaskService.saveOrUpdateProjectTask(projectTask); 38 | 39 | return new ResponseEntity(newPT, HttpStatus.CREATED); 40 | } 41 | 42 | @GetMapping("/all") 43 | public Iterable getAllPTs(){ 44 | return projectTaskService.findAll(); 45 | } 46 | 47 | @GetMapping("/{pt_id}") 48 | public ResponseEntity> getPTById(@PathVariable Long pt_id){ 49 | ProjectTask projectTask = projectTaskService.findById(pt_id); 50 | return new ResponseEntity(projectTask, HttpStatus.OK); 51 | } 52 | 53 | @DeleteMapping("/{pt_id}") 54 | public ResponseEntity> deleteProjectTask(@PathVariable Long pt_id){ 55 | projectTaskService.delete(pt_id); 56 | 57 | return new ResponseEntity("Project Task deleted", HttpStatus.OK); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /projectboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.agileintelligence 7 | projectboard 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | projectboard 12 | project board 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-devtools 40 | runtime 41 | 42 | 43 | com.h2database 44 | h2 45 | runtime 46 | 47 | 48 | mysql 49 | mysql-connector-java 50 | runtime 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-starter-test 55 | test 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /project-board-react/src/components/ProjectBoard.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | import ProjectTaskItem from "./ProjectTask/ProjectTaskItem"; 4 | import { connect } from "react-redux"; 5 | import PropTypes from "prop-types"; 6 | import { getBacklog } from "../actions/projectTaskActions"; 7 | 8 | class ProjectBoard extends Component { 9 | componentDidMount() { 10 | this.props.getBacklog(); 11 | } 12 | render() { 13 | const { project_tasks } = this.props.project_tasks; 14 | 15 | let BoardContent; 16 | let todoItems = []; 17 | let inProgressItems = []; 18 | let doneItems = []; 19 | 20 | const BoardAlgorithm = project_tasks => { 21 | if (project_tasks.length < 1) { 22 | return ( 23 | 24 | No Project Tasks on this board 25 | 26 | ); 27 | } else { 28 | const tasks = project_tasks.map(project_task => ( 29 | 30 | )); 31 | 32 | for (let i = 0; i < tasks.length; i++) { 33 | if (tasks[i].props.project_task.status === "TO_DO") { 34 | todoItems.push(tasks[i]); 35 | } 36 | 37 | if (tasks[i].props.project_task.status === "IN_PROGRESS") { 38 | inProgressItems.push(tasks[i]); 39 | } 40 | 41 | if (tasks[i].props.project_task.status === "DONE") { 42 | doneItems.push(tasks[i]); 43 | } 44 | } 45 | 46 | return ( 47 | 48 | 49 | 50 | 51 | 52 | 53 | TO DO 54 | 55 | 56 | 57 | {todoItems} 58 | 59 | 60 | 61 | 62 | In Progress 63 | 64 | 65 | 66 | {inProgressItems} 67 | 68 | 69 | 70 | 71 | Done 72 | 73 | 74 | 75 | {doneItems} 76 | 77 | 78 | 79 | 80 | ); 81 | } 82 | }; 83 | 84 | BoardContent = BoardAlgorithm(project_tasks); 85 | 86 | return ( 87 | 88 | 89 | Create Project Task 90 | 91 | 92 | 93 | {BoardContent} 94 | 95 | ); 96 | } 97 | } 98 | 99 | ProjectBoard.propTypes = { 100 | getBacklog: PropTypes.func.isRequired, 101 | project_tasks: PropTypes.object.isRequired 102 | }; 103 | 104 | const mapStateToProps = state => ({ 105 | project_tasks: state.project_task 106 | }); 107 | 108 | export default connect( 109 | mapStateToProps, 110 | { getBacklog } 111 | )(ProjectBoard); 112 | -------------------------------------------------------------------------------- /design/ProjectTaskForm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | Project Task Tool 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Project Task Tool 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Back to Board 50 | 51 | Add /Update Project Task 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | Select Status 62 | TO DO 63 | IN PROGRESS 64 | DONE 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 84 | 86 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /project-board-react/src/components/ProjectTask/AddProjectTask.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | import PropTypes from "prop-types"; 4 | import { connect } from "react-redux"; 5 | import { addProjectTask } from "../../actions/projectTaskActions"; 6 | import classnames from "classnames"; 7 | 8 | class AddProjectTask extends Component { 9 | constructor() { 10 | super(); 11 | this.state = { 12 | summary: "", 13 | acceptanceCriteria: "", 14 | status: "", 15 | errors: {} 16 | }; 17 | this.onChange = this.onChange.bind(this); 18 | this.onSubmit = this.onSubmit.bind(this); 19 | } 20 | componentWillReceiveProps(nextProps) { 21 | if (nextProps.errors) { 22 | this.setState({ errors: nextProps.errors }); 23 | } 24 | } 25 | 26 | onChange(e) { 27 | this.setState({ [e.target.name]: e.target.value }); 28 | } 29 | 30 | onSubmit(e) { 31 | e.preventDefault(); 32 | const newProjectTask = { 33 | summary: this.state.summary, 34 | acceptanceCriteria: this.state.acceptanceCriteria, 35 | status: this.state.status 36 | }; 37 | // console.log(newProjectTask); 38 | this.props.addProjectTask(newProjectTask, this.props.history); 39 | } 40 | 41 | render() { 42 | const { errors } = this.state; 43 | return ( 44 | 45 | 46 | 47 | 48 | 49 | Back to Board 50 | 51 | 52 | Add /Update Project Task 53 | 54 | 55 | 56 | 66 | {errors.summary && ( 67 | {errors.summary} 68 | )} 69 | 70 | 71 | 78 | 79 | 80 | 86 | Select Status 87 | TO DO 88 | IN PROGRESS 89 | DONE 90 | 91 | 92 | 96 | 97 | 98 | 99 | 100 | 101 | ); 102 | } 103 | } 104 | 105 | AddProjectTask.propTypes = { 106 | addProjectTask: PropTypes.func.isRequired, 107 | errors: PropTypes.object.isRequired 108 | }; 109 | 110 | const mapStateToProps = state => ({ 111 | errors: state.errors 112 | }); 113 | 114 | export default connect( 115 | mapStateToProps, 116 | { addProjectTask } 117 | )(AddProjectTask); 118 | -------------------------------------------------------------------------------- /project-board-react/src/components/ProjectTask/UpdateProjectTask.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { connect } from "react-redux"; 3 | import classnames from "classnames"; 4 | import PropTypes from "prop-types"; 5 | import { 6 | getProjectTask, 7 | addProjectTask 8 | } from "../../actions/projectTaskActions"; 9 | 10 | class UpdateProjectTask extends Component { 11 | constructor() { 12 | super(); 13 | this.state = { 14 | id: "", 15 | summary: "", 16 | acceptanceCriteria: "", 17 | status: "", 18 | errors: {} 19 | }; 20 | this.onChange = this.onChange.bind(this); 21 | this.onSubmit = this.onSubmit.bind(this); 22 | } 23 | 24 | componentWillReceiveProps(nextProps) { 25 | if (nextProps.errors) { 26 | this.setState({ errors: nextProps.errors }); 27 | } 28 | 29 | const { id, summary, acceptanceCriteria, status } = nextProps.project_task; 30 | 31 | this.setState({ 32 | id, 33 | summary, 34 | acceptanceCriteria, 35 | status 36 | }); 37 | } 38 | 39 | componentDidMount() { 40 | const { pt_id } = this.props.match.params; 41 | this.props.getProjectTask(pt_id); 42 | } 43 | 44 | onSubmit(e) { 45 | e.preventDefault(); 46 | const updatedTask = { 47 | id: this.state.id, 48 | summary: this.state.summary, 49 | acceptanceCriteria: this.state.acceptanceCriteria, 50 | status: this.state.status 51 | }; 52 | 53 | this.props.addProjectTask(updatedTask, this.props.history); 54 | } 55 | 56 | onChange(e) { 57 | this.setState({ [e.target.name]: e.target.value }); 58 | } 59 | render() { 60 | const { errors } = this.state; 61 | return ( 62 | 63 | 64 | 65 | 66 | 67 | Back to Board 68 | 69 | 70 | Add /Update Project Task 71 | 72 | 73 | 74 | 84 | {errors.summary && ( 85 | {errors.summary} 86 | )} 87 | 88 | 89 | 96 | 97 | 98 | 104 | Select Status 105 | TO DO 106 | IN PROGRESS 107 | DONE 108 | 109 | 110 | 114 | 115 | 116 | 117 | 118 | 119 | ); 120 | } 121 | } 122 | 123 | UpdateProjectTask.propTypes = { 124 | project_task: PropTypes.object.isRequired, 125 | errors: PropTypes.object.isRequired, 126 | getProjectTask: PropTypes.func.isRequired, 127 | addProjectTask: PropTypes.func.isRequired 128 | }; 129 | 130 | const mapStateToProps = state => ({ 131 | project_task: state.project_task.project_task, 132 | errors: state.errors 133 | }); 134 | 135 | export default connect( 136 | mapStateToProps, 137 | { getProjectTask, addProjectTask } 138 | )(UpdateProjectTask); 139 | -------------------------------------------------------------------------------- /design/ProjectBoard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | Project Task Tool 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Project Task Tool 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Create Project Task 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | TO DO 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | ID: projectSequence 61 | 62 | 63 | summary 64 | 65 | acceptanceCriteria 66 | 67 | 68 | View / Update 69 | 70 | 71 | 72 | Delete 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | In Progress 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Done 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 115 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /project-board-react/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read http://bit.ly/CRA-PWA. 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | installingWorker.onstatechange = () => { 64 | if (installingWorker.state === 'installed') { 65 | if (navigator.serviceWorker.controller) { 66 | // At this point, the updated precached content has been fetched, 67 | // but the previous service worker will still serve the older 68 | // content until all client tabs are closed. 69 | console.log( 70 | 'New content is available and will be used when all ' + 71 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.' 72 | ); 73 | 74 | // Execute callback 75 | if (config && config.onUpdate) { 76 | config.onUpdate(registration); 77 | } 78 | } else { 79 | // At this point, everything has been precached. 80 | // It's the perfect time to display a 81 | // "Content is cached for offline use." message. 82 | console.log('Content is cached for offline use.'); 83 | 84 | // Execute callback 85 | if (config && config.onSuccess) { 86 | config.onSuccess(registration); 87 | } 88 | } 89 | } 90 | }; 91 | }; 92 | }) 93 | .catch(error => { 94 | console.error('Error during service worker registration:', error); 95 | }); 96 | } 97 | 98 | function checkValidServiceWorker(swUrl, config) { 99 | // Check if the service worker can be found. If it can't reload the page. 100 | fetch(swUrl) 101 | .then(response => { 102 | // Ensure service worker exists, and that we really are getting a JS file. 103 | if ( 104 | response.status === 404 || 105 | response.headers.get('content-type').indexOf('javascript') === -1 106 | ) { 107 | // No service worker found. Probably a different app. Reload the page. 108 | navigator.serviceWorker.ready.then(registration => { 109 | registration.unregister().then(() => { 110 | window.location.reload(); 111 | }); 112 | }); 113 | } else { 114 | // Service worker found. Proceed as normal. 115 | registerValidSW(swUrl, config); 116 | } 117 | }) 118 | .catch(() => { 119 | console.log( 120 | 'No internet connection found. App is running in offline mode.' 121 | ); 122 | }); 123 | } 124 | 125 | export function unregister() { 126 | if ('serviceWorker' in navigator) { 127 | navigator.serviceWorker.ready.then(registration => { 128 | registration.unregister(); 129 | }); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /projectboard/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /projectboard/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | true 33 | DEFINITION_ORDER 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Java 50 | 51 | 52 | Serialization issuesJava 53 | 54 | 55 | 56 | 57 | SerializableInnerClassHasSerialVersionUIDField 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 1540147658904 131 | 132 | 133 | 1540147658904 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | Python 2.7.10 virtualenv at ~/Desktop/DojoAssignments/Python/PY2DJANGO/DjangoProjects/djangoEnv interpreter library 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 1.8 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 1.8 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | antlr-2.7.7 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | -------------------------------------------------------------------------------- /project-board-react/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | Below you will find some information on how to perform common tasks. 4 | You can find the most recent version of this guide [here](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md). 5 | 6 | ## Table of Contents 7 | 8 | - [Updating to New Releases](#updating-to-new-releases) 9 | - [Sending Feedback](#sending-feedback) 10 | - [Folder Structure](#folder-structure) 11 | - [Available Scripts](#available-scripts) 12 | - [npm start](#npm-start) 13 | - [npm test](#npm-test) 14 | - [npm run build](#npm-run-build) 15 | - [npm run eject](#npm-run-eject) 16 | - [Supported Browsers](#supported-browsers) 17 | - [Supported Language Features](#supported-language-features) 18 | - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor) 19 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor) 20 | - [Debugging in the Editor](#debugging-in-the-editor) 21 | - [Formatting Code Automatically](#formatting-code-automatically) 22 | - [Changing the Page ``](#changing-the-page-title) 23 | - [Installing a Dependency](#installing-a-dependency) 24 | - [Importing a Component](#importing-a-component) 25 | - [Code Splitting](#code-splitting) 26 | - [Adding a Stylesheet](#adding-a-stylesheet) 27 | - [Adding a CSS Modules Stylesheet](#adding-a-css-modules-stylesheet) 28 | - [Adding a Sass Stylesheet](#adding-a-sass-stylesheet) 29 | - [Post-Processing CSS](#post-processing-css) 30 | - [Adding Images, Fonts, and Files](#adding-images-fonts-and-files) 31 | - [Adding SVGs](#adding-svgs) 32 | - [Using the `public` Folder](#using-the-public-folder) 33 | - [Changing the HTML](#changing-the-html) 34 | - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system) 35 | - [When to Use the `public` Folder](#when-to-use-the-public-folder) 36 | - [Using Global Variables](#using-global-variables) 37 | - [Adding Bootstrap](#adding-bootstrap) 38 | - [Using a Custom Theme](#using-a-custom-theme) 39 | - [Adding Flow](#adding-flow) 40 | - [Adding Relay](#adding-relay) 41 | - [Adding a Router](#adding-a-router) 42 | - [Adding Custom Environment Variables](#adding-custom-environment-variables) 43 | - [Referencing Environment Variables in the HTML](#referencing-environment-variables-in-the-html) 44 | - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell) 45 | - [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env) 46 | - [Can I Use Decorators?](#can-i-use-decorators) 47 | - [Fetching Data with AJAX Requests](#fetching-data-with-ajax-requests) 48 | - [Integrating with an API Backend](#integrating-with-an-api-backend) 49 | - [Node](#node) 50 | - [Ruby on Rails](#ruby-on-rails) 51 | - [Proxying API Requests in Development](#proxying-api-requests-in-development) 52 | - ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy) 53 | - [Configuring the Proxy Manually](#configuring-the-proxy-manually) 54 | - [Using HTTPS in Development](#using-https-in-development) 55 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) 56 | - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files) 57 | - [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page) 58 | - [Running Tests](#running-tests) 59 | - [Filename Conventions](#filename-conventions) 60 | - [Command Line Interface](#command-line-interface) 61 | - [Version Control Integration](#version-control-integration) 62 | - [Writing Tests](#writing-tests) 63 | - [Testing Components](#testing-components) 64 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries) 65 | - [Initializing Test Environment](#initializing-test-environment) 66 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests) 67 | - [Coverage Reporting](#coverage-reporting) 68 | - [Continuous Integration](#continuous-integration) 69 | - [Disabling jsdom](#disabling-jsdom) 70 | - [Snapshot Testing](#snapshot-testing) 71 | - [Editor Integration](#editor-integration) 72 | - [Debugging Tests](#debugging-tests) 73 | - [Debugging Tests in Chrome](#debugging-tests-in-chrome) 74 | - [Debugging Tests in Visual Studio Code](#debugging-tests-in-visual-studio-code) 75 | - [Developing Components in Isolation](#developing-components-in-isolation) 76 | - [Getting Started with Storybook](#getting-started-with-storybook) 77 | - [Getting Started with Styleguidist](#getting-started-with-styleguidist) 78 | - [Publishing Components to npm](#publishing-components-to-npm) 79 | - [Making a Progressive Web App](#making-a-progressive-web-app) 80 | - [Why Opt-in?](#why-opt-in) 81 | - [Offline-First Considerations](#offline-first-considerations) 82 | - [Progressive Web App Metadata](#progressive-web-app-metadata) 83 | - [Analyzing the Bundle Size](#analyzing-the-bundle-size) 84 | - [Deployment](#deployment) 85 | - [Static Server](#static-server) 86 | - [Other Solutions](#other-solutions) 87 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing) 88 | - [Building for Relative Paths](#building-for-relative-paths) 89 | - [Customizing Environment Variables for Arbitrary Build Environments](#customizing-environment-variables-for-arbitrary-build-environments) 90 | - [Azure](#azure) 91 | - [Firebase](#firebase) 92 | - [GitHub Pages](#github-pages) 93 | - [Heroku](#heroku) 94 | - [Netlify](#netlify) 95 | - [Now](#now) 96 | - [S3 and CloudFront](#s3-and-cloudfront) 97 | - [Surge](#surge) 98 | - [Advanced Configuration](#advanced-configuration) 99 | - [Troubleshooting](#troubleshooting-1) 100 | - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes) 101 | - [`npm test` hangs or crashes on macOS Sierra](#npm-test-hangs-or-crashes-on-macos-sierra) 102 | - [`npm run build` exits too early](#npm-run-build-exits-too-early) 103 | - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku) 104 | - [`npm run build` fails to minify](#npm-run-build-fails-to-minify) 105 | - [Moment.js locales are missing](#momentjs-locales-are-missing) 106 | - [Alternatives to Ejecting](#alternatives-to-ejecting) 107 | - [Something Missing?](#something-missing) 108 | 109 | ## Updating to New Releases 110 | 111 | Create React App is divided into two packages: 112 | 113 | - `create-react-app` is a global command-line utility that you use to create new projects. 114 | - `react-scripts` is a development dependency in the generated projects (including this one). 115 | 116 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`. 117 | 118 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically. 119 | 120 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions. 121 | 122 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` (or `yarn install`) in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes. 123 | 124 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly. 125 | 126 | ## Sending Feedback 127 | 128 | We are always open to [your feedback](https://github.com/facebook/create-react-app/issues). 129 | 130 | ## Folder Structure 131 | 132 | After creation, your project should look like this: 133 | 134 | ``` 135 | my-app/ 136 | README.md 137 | node_modules/ 138 | package.json 139 | public/ 140 | index.html 141 | favicon.ico 142 | src/ 143 | App.css 144 | App.js 145 | App.test.js 146 | index.css 147 | index.js 148 | logo.svg 149 | ``` 150 | 151 | For the project to build, **these files must exist with exact filenames**: 152 | 153 | - `public/index.html` is the page template; 154 | - `src/index.js` is the JavaScript entry point. 155 | 156 | You can delete or rename the other files. 157 | 158 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack. 159 | You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them. 160 | 161 | Only files inside `public` can be used from `public/index.html`. 162 | Read instructions below for using assets from JavaScript and HTML. 163 | 164 | You can, however, create more top-level directories. 165 | They will not be included in the production build so you can use them for things like documentation. 166 | 167 | If you have Git installed and your project is not part of a larger repository, then a new repository will be initialized resulting in an additional `.git/` top-level directory. 168 | 169 | ## Available Scripts 170 | 171 | In the project directory, you can run: 172 | 173 | ### `npm start` 174 | 175 | Runs the app in the development mode. 176 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 177 | 178 | The page will reload if you make edits. 179 | You will also see any lint errors in the console. 180 | 181 | ### `npm test` 182 | 183 | Launches the test runner in the interactive watch mode. 184 | See the section about [running tests](#running-tests) for more information. 185 | 186 | ### `npm run build` 187 | 188 | Builds the app for production to the `build` folder. 189 | It correctly bundles React in production mode and optimizes the build for the best performance. 190 | 191 | The build is minified and the filenames include the hashes. 192 | Your app is ready to be deployed! 193 | 194 | See the section about [deployment](#deployment) for more information. 195 | 196 | ### `npm run eject` 197 | 198 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 199 | 200 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 201 | 202 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 203 | 204 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 205 | 206 | ## Supported Browsers 207 | 208 | By default, the generated project supports all modern browsers. 209 | Support for Internet Explorer 9, 10, and 11 requires [polyfills](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md). 210 | 211 | ### Supported Language Features 212 | 213 | This project supports a superset of the latest JavaScript standard. 214 | In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports: 215 | 216 | - [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016). 217 | - [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017). 218 | - [Object Rest/Spread Properties](https://github.com/tc39/proposal-object-rest-spread) (ES2018). 219 | - [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal) 220 | - [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal). 221 | - [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flow.org/) syntax. 222 | 223 | Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-). 224 | 225 | While we recommend using experimental proposals with some caution, Facebook heavily uses these features in the product code, so we intend to provide [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) if any of these proposals change in the future. 226 | 227 | Note that **this project includes no [polyfills](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md)** by default. 228 | 229 | If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are [including the appropriate polyfills manually](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md), or that the browsers you are targeting already support them. 230 | 231 | ## Syntax Highlighting in the Editor 232 | 233 | To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered. 234 | 235 | ## Displaying Lint Output in the Editor 236 | 237 | > Note: this feature is available with `react-scripts@0.2.0` and higher. 238 | > It also only works with npm 3 or higher. 239 | 240 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint. 241 | 242 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do. 243 | 244 | You would need to install an ESLint plugin for your editor first. Then, add a file called `.eslintrc` to the project root: 245 | 246 | ```js 247 | { 248 | "extends": "react-app" 249 | } 250 | ``` 251 | 252 | Now your editor should report the linting warnings. 253 | 254 | Note that even if you edit your `.eslintrc` file further, these changes will **only affect the editor integration**. They won’t affect the terminal and in-browser lint output. This is because Create React App intentionally provides a minimal set of rules that find common mistakes. 255 | 256 | If you want to enforce a coding style for your project, consider using [Prettier](https://github.com/jlongster/prettier) instead of ESLint style rules. 257 | 258 | ## Debugging in the Editor 259 | 260 | **This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) and [WebStorm](https://www.jetbrains.com/webstorm/).** 261 | 262 | Visual Studio Code and WebStorm support debugging out of the box with Create React App. This enables you as a developer to write and debug your React code without leaving the editor, and most importantly it enables you to have a continuous development workflow, where context switching is minimal, as you don’t have to switch between tools. 263 | 264 | ### Visual Studio Code 265 | 266 | You would need to have the latest version of [VS Code](https://code.visualstudio.com) and VS Code [Chrome Debugger Extension](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) installed. 267 | 268 | Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory. 269 | 270 | ```json 271 | { 272 | "version": "0.2.0", 273 | "configurations": [ 274 | { 275 | "name": "Chrome", 276 | "type": "chrome", 277 | "request": "launch", 278 | "url": "http://localhost:3000", 279 | "webRoot": "${workspaceRoot}/src", 280 | "sourceMapPathOverrides": { 281 | "webpack:///src/*": "${webRoot}/*" 282 | } 283 | } 284 | ] 285 | } 286 | ``` 287 | 288 | > Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). 289 | 290 | Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor. 291 | 292 | Having problems with VS Code Debugging? Please see their [troubleshooting guide](https://github.com/Microsoft/vscode-chrome-debug/blob/master/README.md#troubleshooting). 293 | 294 | ### WebStorm 295 | 296 | You would need to have [WebStorm](https://www.jetbrains.com/webstorm/) and [JetBrains IDE Support](https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji) Chrome extension installed. 297 | 298 | In the WebStorm menu `Run` select `Edit Configurations...`. Then click `+` and select `JavaScript Debug`. Paste `http://localhost:3000` into the URL field and save the configuration. 299 | 300 | > Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration). 301 | 302 | Start your app by running `npm start`, then press `^D` on macOS or `F9` on Windows and Linux or click the green debug icon to start debugging in WebStorm. 303 | 304 | The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine. 305 | 306 | ## Formatting Code Automatically 307 | 308 | Prettier is an opinionated code formatter with support for JavaScript, CSS and JSON. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's GitHub page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/). 309 | 310 | To format our code whenever we make a commit in git, we need to install the following dependencies: 311 | 312 | ```sh 313 | npm install --save husky lint-staged prettier 314 | ``` 315 | 316 | Alternatively you may use `yarn`: 317 | 318 | ```sh 319 | yarn add husky lint-staged prettier 320 | ``` 321 | 322 | - `husky` makes it easy to use githooks as if they are npm scripts. 323 | - `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8). 324 | - `prettier` is the JavaScript formatter we will run before commits. 325 | 326 | Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root. 327 | 328 | Add the following field to the `package.json` section: 329 | 330 | ```diff 331 | + "husky": { 332 | + "hooks": { 333 | + "pre-commit": "lint-staged" 334 | + } 335 | + } 336 | ``` 337 | 338 | Next we add a 'lint-staged' field to the `package.json`, for example: 339 | 340 | ```diff 341 | "dependencies": { 342 | // ... 343 | }, 344 | + "lint-staged": { 345 | + "src/**/*.{js,jsx,json,css}": [ 346 | + "prettier --single-quote --write", 347 | + "git add" 348 | + ] 349 | + }, 350 | "scripts": { 351 | ``` 352 | 353 | Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time. 354 | 355 | Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://prettier.io/docs/en/editors.html) on the Prettier GitHub page. 356 | 357 | ## Changing the Page `` 358 | 359 | You can find the source HTML file in the `public` folder of the generated project. You may edit the `` tag in it to change the title from “React App” to anything else. 360 | 361 | Note that normally you wouldn’t edit files in the `public` folder very often. For example, [adding a stylesheet](#adding-a-stylesheet) is done without touching the HTML. 362 | 363 | If you need to dynamically update the page title based on the content, you can use the browser [`document.title`](https://developer.mozilla.org/en-US/docs/Web/API/Document/title) API. For more complex scenarios when you want to change the title from React components, you can use [React Helmet](https://github.com/nfl/react-helmet), a third party library. 364 | 365 | If you use a custom server for your app in production and want to modify the title before it gets sent to the browser, you can follow advice in [this section](#generating-dynamic-meta-tags-on-the-server). Alternatively, you can pre-build each page as a static HTML file which then loads the JavaScript bundle, which is covered [here](#pre-rendering-into-static-html-files). 366 | 367 | ## Installing a Dependency 368 | 369 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`: 370 | 371 | ```sh 372 | npm install --save react-router-dom 373 | ``` 374 | 375 | Alternatively you may use `yarn`: 376 | 377 | ```sh 378 | yarn add react-router-dom 379 | ``` 380 | 381 | This works for any library, not just `react-router-dom`. 382 | 383 | ## Importing a Component 384 | 385 | This project setup supports ES6 modules thanks to Webpack. 386 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead. 387 | 388 | For example: 389 | 390 | ### `Button.js` 391 | 392 | ```js 393 | import React, { Component } from 'react'; 394 | 395 | class Button extends Component { 396 | render() { 397 | // ... 398 | } 399 | } 400 | 401 | export default Button; // Don’t forget to use export default! 402 | ``` 403 | 404 | ### `DangerButton.js` 405 | 406 | ```js 407 | import React, { Component } from 'react'; 408 | import Button from './Button'; // Import a component from another file 409 | 410 | class DangerButton extends Component { 411 | render() { 412 | return ; 413 | } 414 | } 415 | 416 | export default DangerButton; 417 | ``` 418 | 419 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes. 420 | 421 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`. 422 | 423 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like. 424 | 425 | Learn more about ES6 modules: 426 | 427 | - [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281) 428 | - [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) 429 | - [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) 430 | 431 | ## Code Splitting 432 | 433 | Instead of downloading the entire app before users can use it, code splitting allows you to split your code into small chunks which you can then load on demand. 434 | 435 | This project setup supports code splitting via [dynamic `import()`](http://2ality.com/2017/01/import-operator.html#loading-code-on-demand). Its [proposal](https://github.com/tc39/proposal-dynamic-import) is in stage 3. The `import()` function-like form takes the module name as an argument and returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which always resolves to the namespace object of the module. 436 | 437 | Here is an example: 438 | 439 | ### `moduleA.js` 440 | 441 | ```js 442 | const moduleA = 'Hello'; 443 | 444 | export { moduleA }; 445 | ``` 446 | 447 | ### `App.js` 448 | 449 | ```js 450 | import React, { Component } from 'react'; 451 | 452 | class App extends Component { 453 | handleClick = () => { 454 | import('./moduleA') 455 | .then(({ moduleA }) => { 456 | // Use moduleA 457 | }) 458 | .catch(err => { 459 | // Handle failure 460 | }); 461 | }; 462 | 463 | render() { 464 | return ( 465 | 466 | Load 467 | 468 | ); 469 | } 470 | } 471 | 472 | export default App; 473 | ``` 474 | 475 | This will make `moduleA.js` and all its unique dependencies as a separate chunk that only loads after the user clicks the 'Load' button. 476 | 477 | You can also use it with `async` / `await` syntax if you prefer it. 478 | 479 | ### With React Router 480 | 481 | If you are using React Router check out [this tutorial](http://serverless-stack.com/chapters/code-splitting-in-create-react-app.html) on how to use code splitting with it. You can find the companion GitHub repository [here](https://github.com/AnomalyInnovations/serverless-stack-demo-client/tree/code-splitting-in-create-react-app). 482 | 483 | Also check out the [Code Splitting](https://reactjs.org/docs/code-splitting.html) section in React documentation. 484 | 485 | ## Adding a Stylesheet 486 | 487 | This project setup uses [Webpack](https://webpack.js.org/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**: 488 | 489 | ### `Button.css` 490 | 491 | ```css 492 | .Button { 493 | padding: 20px; 494 | } 495 | ``` 496 | 497 | ### `Button.js` 498 | 499 | ```js 500 | import React, { Component } from 'react'; 501 | import './Button.css'; // Tell Webpack that Button.js uses these styles 502 | 503 | class Button extends Component { 504 | render() { 505 | // You can use them as regular CSS styles 506 | return ; 507 | } 508 | } 509 | ``` 510 | 511 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-blog/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack. 512 | 513 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output. 514 | 515 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool. 516 | 517 | ## Adding a CSS Modules Stylesheet 518 | 519 | > Note: this feature is available with `react-scripts@2.0.0` and higher. 520 | 521 | This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the `[name].module.css` file naming convention. CSS Modules allows the scoping of CSS by automatically creating a unique classname of the format `[filename]\_[classname]\_\_[hash]`. 522 | 523 | > **Tip:** Should you want to preprocess a stylesheet with Sass then make sure to [follow the installation instructions](#adding-a-sass-stylesheet) and then change the stylesheet file extension as follows: `[name].module.scss` or `[name].module.sass`. 524 | 525 | CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules [here](https://css-tricks.com/css-modules-part-1-need/). 526 | 527 | ### `Button.module.css` 528 | 529 | ```css 530 | .error { 531 | background-color: red; 532 | } 533 | ``` 534 | 535 | ### `another-stylesheet.css` 536 | 537 | ```css 538 | .error { 539 | color: red; 540 | } 541 | ``` 542 | 543 | ### `Button.js` 544 | 545 | ```js 546 | import React, { Component } from 'react'; 547 | import styles from './Button.module.css'; // Import css modules stylesheet as styles 548 | import './another-stylesheet.css'; // Import regular stylesheet 549 | 550 | class Button extends Component { 551 | render() { 552 | // reference as a js object 553 | return Error Button; 554 | } 555 | } 556 | ``` 557 | 558 | ### Result 559 | 560 | No clashes from other `.error` class names 561 | 562 | ```html 563 | 564 | 565 | ``` 566 | 567 | **This is an optional feature.** Regular `` stylesheets and CSS files are fully supported. CSS Modules are turned on for files ending with the `.module.css` extension. 568 | 569 | ## Adding a Sass Stylesheet 570 | 571 | > Note: this feature is available with `react-scripts@2.0.0` and higher. 572 | 573 | Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `` and `` components, we recommend creating a `` component with its own `.Button` styles, that both `` and `` can render (but [not inherit](https://facebook.github.io/react/docs/composition-vs-inheritance.html)). 574 | 575 | Following this rule often makes CSS preprocessors less useful, as features like mixins and nesting are replaced by component composition. You can, however, integrate a CSS preprocessor if you find it valuable. 576 | 577 | To use Sass, first install `node-sass`: 578 | 579 | ```bash 580 | $ npm install node-sass --save 581 | $ # or 582 | $ yarn add node-sass 583 | ``` 584 | 585 | Now you can rename `src/App.css` to `src/App.scss` and update `src/App.js` to import `src/App.scss`. 586 | This file and any other file will be automatically compiled if imported with the extension `.scss` or `.sass`. 587 | 588 | To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions. 589 | 590 | This will allow you to do imports like 591 | 592 | ```scss 593 | @import 'styles/_colors.scss'; // assuming a styles directory under src/ 594 | @import '~nprogress/nprogress'; // importing a css file from the nprogress node module 595 | ``` 596 | 597 | > **Tip:** You can opt into using this feature with [CSS modules](#adding-a-css-modules-stylesheet) too! 598 | 599 | > **Note:** You must prefix imports from `node_modules` with `~` as displayed above. 600 | 601 | > **Note:** If you're using Flow, add the following to your `.flowconfig` so it'll recognize the `.sass` or `.scss` imports. 602 | 603 | ``` 604 | [options] 605 | module.file_ext=.sass 606 | module.file_ext=.scss 607 | ``` 608 | 609 | ## Post-Processing CSS 610 | 611 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it. 612 | 613 | Support for new CSS features like the [`all` property](https://developer.mozilla.org/en-US/docs/Web/CSS/all), [`break` properties](https://www.w3.org/TR/css-break-3/#breaking-controls), [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables), and [media query ranges](https://www.w3.org/TR/mediaqueries-4/#range-context) are automatically polyfilled to add support for older browsers. 614 | 615 | You can customize your target support browsers by adjusting the `browserslist` key in `package.json` according to the [Browserslist specification](https://github.com/browserslist/browserslist#readme). 616 | 617 | For example, this: 618 | 619 | ```css 620 | .App { 621 | display: flex; 622 | flex-direction: row; 623 | align-items: center; 624 | } 625 | ``` 626 | 627 | becomes this: 628 | 629 | ```css 630 | .App { 631 | display: -webkit-box; 632 | display: -ms-flexbox; 633 | display: flex; 634 | -webkit-box-orient: horizontal; 635 | -webkit-box-direction: normal; 636 | -ms-flex-direction: row; 637 | flex-direction: row; 638 | -webkit-box-align: center; 639 | -ms-flex-align: center; 640 | align-items: center; 641 | } 642 | ``` 643 | 644 | If you need to disable autoprefixing for some reason, [follow this section](https://github.com/postcss/autoprefixer#disabling). 645 | 646 | [CSS Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout) prefixing is disabled by default, but it will **not** strip manual prefixing. 647 | If you'd like to opt-in to CSS Grid prefixing, [first familiarize yourself about its limitations](https://github.com/postcss/autoprefixer#does-autoprefixer-polyfill-grid-layout-for-ie). 648 | To enable CSS Grid prefixing, add `/* autoprefixer grid: on */` to the top of your CSS file. 649 | 650 | ## Adding Images, Fonts, and Files 651 | 652 | With Webpack, using static assets like images and fonts works similarly to CSS. 653 | 654 | You can **`import` a file right in a JavaScript module**. This tells Webpack to include that file in the bundle. Unlike CSS imports, importing a file gives you a string value. This value is the final path you can reference in your code, e.g. as the `src` attribute of an image or the `href` of a link to a PDF. 655 | 656 | To reduce the number of requests to the server, importing images that are less than 10,000 bytes returns a [data URI](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) instead of a path. This applies to the following file extensions: bmp, gif, jpg, jpeg, and png. SVG files are excluded due to [#1153](https://github.com/facebook/create-react-app/issues/1153). 657 | 658 | Here is an example: 659 | 660 | ```js 661 | import React from 'react'; 662 | import logo from './logo.png'; // Tell Webpack this JS file uses this image 663 | 664 | console.log(logo); // /logo.84287d09.png 665 | 666 | function Header() { 667 | // Import result is the URL of your image 668 | return ; 669 | } 670 | 671 | export default Header; 672 | ``` 673 | 674 | This ensures that when the project is built, Webpack will correctly move the images into the build folder, and provide us with correct paths. 675 | 676 | This works in CSS too: 677 | 678 | ```css 679 | .Logo { 680 | background-image: url(./logo.png); 681 | } 682 | ``` 683 | 684 | Webpack finds all relative module references in CSS (they start with `./`) and replaces them with the final paths from the compiled bundle. If you make a typo or accidentally delete an important file, you will see a compilation error, just like when you import a non-existent JavaScript module. The final filenames in the compiled bundle are generated by Webpack from content hashes. If the file content changes in the future, Webpack will give it a different name in production so you don’t need to worry about long-term caching of assets. 685 | 686 | Please be advised that this is also a custom feature of Webpack. 687 | 688 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images). 689 | An alternative way of handling static assets is described in the next section. 690 | 691 | ### Adding SVGs 692 | 693 | > Note: this feature is available with `react-scripts@2.0.0` and higher. 694 | 695 | One way to add SVG files was described in the section above. You can also import SVGs directly as React components. You can use either of the two approaches. In your code it would look like this: 696 | 697 | ```js 698 | import { ReactComponent as Logo } from './logo.svg'; 699 | const App = () => ( 700 | 701 | {/* Logo is an actual React component */} 702 | 703 | 704 | ); 705 | ``` 706 | 707 | This is handy if you don't want to load SVG as a separate file. Don't forget the curly braces in the import! The `ReactComponent` import name is special and tells Create React App that you want a React component that renders an SVG, rather than its filename. 708 | 709 | ## Using the `public` Folder 710 | 711 | > Note: this feature is available with `react-scripts@0.5.0` and higher. 712 | 713 | ### Changing the HTML 714 | 715 | The `public` folder contains the HTML file so you can tweak it, for example, to [set the page title](#changing-the-page-title). 716 | The ` 1301 | ``` 1302 | 1303 | Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.** 1304 | 1305 | ## Running Tests 1306 | 1307 | > Note: this feature is available with `react-scripts@0.3.0` and higher. 1308 | 1309 | > [Read the migration guide to learn how to enable it in older projects!](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md#migrating-from-023-to-030) 1310 | 1311 | Create React App uses [Jest](https://facebook.github.io/jest/) as its test runner. To prepare for this integration, we did a [major revamp](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html) of Jest so if you heard bad things about it years ago, give it another try. 1312 | 1313 | Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser. This lets us enable fast iteration speed and prevent flakiness. 1314 | 1315 | While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks. 1316 | 1317 | We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App. 1318 | 1319 | ### Filename Conventions 1320 | 1321 | Jest will look for test files with any of the following popular naming conventions: 1322 | 1323 | - Files with `.js` suffix in `__tests__` folders. 1324 | - Files with `.test.js` suffix. 1325 | - Files with `.spec.js` suffix. 1326 | 1327 | The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder. 1328 | 1329 | We recommend to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects. 1330 | 1331 | ### Command Line Interface 1332 | 1333 | When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code. 1334 | 1335 | The watcher includes an interactive command-line interface with the ability to run all tests, or focus on a search pattern. It is designed this way so that you can keep it open and enjoy fast re-runs. You can learn the commands from the “Watch Usage” note that the watcher prints after every run: 1336 | 1337 |  1338 | 1339 | ### Version Control Integration 1340 | 1341 | By default, when you run `npm test`, Jest will only run the tests related to files changed since the last commit. This is an optimization designed to make your tests run fast regardless of how many tests you have. However it assumes that you don’t often commit the code that doesn’t pass the tests. 1342 | 1343 | Jest will always explicitly mention that it only ran tests related to the files changed since the last commit. You can also press `a` in the watch mode to force Jest to run all tests. 1344 | 1345 | Jest will always run all tests on a [continuous integration](#continuous-integration) server or if the project is not inside a Git or Mercurial repository. 1346 | 1347 | ### Writing Tests 1348 | 1349 | To create tests, add `it()` (or `test()`) blocks with the name of the test and its code. You may optionally wrap them in `describe()` blocks for logical grouping but this is neither required nor recommended. 1350 | 1351 | Jest provides a built-in `expect()` global function for making assertions. A basic test could look like this: 1352 | 1353 | ```js 1354 | import sum from './sum'; 1355 | 1356 | it('sums numbers', () => { 1357 | expect(sum(1, 2)).toEqual(3); 1358 | expect(sum(2, 2)).toEqual(4); 1359 | }); 1360 | ``` 1361 | 1362 | All `expect()` matchers supported by Jest are [extensively documented here](https://facebook.github.io/jest/docs/en/expect.html#content). 1363 | You can also use [`jest.fn()` and `expect(fn).toBeCalled()`](https://facebook.github.io/jest/docs/en/expect.html#tohavebeencalled) to create “spies” or mock functions. 1364 | 1365 | ### Testing Components 1366 | 1367 | There is a broad spectrum of component testing techniques. They range from a “smoke test” verifying that a component renders without throwing, to shallow rendering and testing some of the output, to full rendering and testing component lifecycle and state changes. 1368 | 1369 | Different projects choose different testing tradeoffs based on how often components change, and how much logic they contain. If you haven’t decided on a testing strategy yet, we recommend that you start with creating simple smoke tests for your components: 1370 | 1371 | ```js 1372 | import React from 'react'; 1373 | import ReactDOM from 'react-dom'; 1374 | import App from './App'; 1375 | 1376 | it('renders without crashing', () => { 1377 | const div = document.createElement('div'); 1378 | ReactDOM.render(, div); 1379 | }); 1380 | ``` 1381 | 1382 | This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot of value with very little effort so they are great as a starting point, and this is the test you will find in `src/App.test.js`. 1383 | 1384 | When you encounter bugs caused by changing components, you will gain a deeper insight into which parts of them are worth testing in your application. This might be a good time to introduce more specific tests asserting specific expected output or behavior. 1385 | 1386 | If you’d like to test components in isolation from the child components they render, we recommend using [`shallow()` rendering API](http://airbnb.io/enzyme/docs/api/shallow.html) from [Enzyme](http://airbnb.io/enzyme/). To install it, run: 1387 | 1388 | ```sh 1389 | npm install --save enzyme enzyme-adapter-react-16 react-test-renderer 1390 | ``` 1391 | 1392 | Alternatively you may use `yarn`: 1393 | 1394 | ```sh 1395 | yarn add enzyme enzyme-adapter-react-16 react-test-renderer 1396 | ``` 1397 | 1398 | As of Enzyme 3, you will need to install Enzyme along with an Adapter corresponding to the version of React you are using. (The examples above use the adapter for React 16.) 1399 | 1400 | The adapter will also need to be configured in your [global setup file](#initializing-test-environment): 1401 | 1402 | #### `src/setupTests.js` 1403 | 1404 | ```js 1405 | import { configure } from 'enzyme'; 1406 | import Adapter from 'enzyme-adapter-react-16'; 1407 | 1408 | configure({ adapter: new Adapter() }); 1409 | ``` 1410 | 1411 | > Note: Keep in mind that if you decide to "eject" before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it. [Read here](#initializing-test-environment) to learn how to add this after ejecting. 1412 | 1413 | Now you can write a smoke test with it: 1414 | 1415 | ```js 1416 | import React from 'react'; 1417 | import { shallow } from 'enzyme'; 1418 | import App from './App'; 1419 | 1420 | it('renders without crashing', () => { 1421 | shallow(); 1422 | }); 1423 | ``` 1424 | 1425 | Unlike the previous smoke test using `ReactDOM.render()`, this test only renders `` and doesn’t go deeper. For example, even if `` itself renders a `` that throws, this test will pass. Shallow rendering is great for isolated unit tests, but you may still want to create some full rendering tests to ensure the components integrate correctly. Enzyme supports [full rendering with `mount()`](http://airbnb.io/enzyme/docs/api/mount.html), and you can also use it for testing state changes and component lifecycle. 1426 | 1427 | You can read the [Enzyme documentation](http://airbnb.io/enzyme/) for more testing techniques. Enzyme documentation uses Chai and Sinon for assertions but you don’t have to use them because Jest provides built-in `expect()` and `jest.fn()` for spies. 1428 | 1429 | Here is an example from Enzyme documentation that asserts specific output, rewritten to use Jest matchers: 1430 | 1431 | ```js 1432 | import React from 'react'; 1433 | import { shallow } from 'enzyme'; 1434 | import App from './App'; 1435 | 1436 | it('renders welcome message', () => { 1437 | const wrapper = shallow(); 1438 | const welcome = Welcome to React; 1439 | // expect(wrapper.contains(welcome)).toBe(true); 1440 | expect(wrapper.contains(welcome)).toEqual(true); 1441 | }); 1442 | ``` 1443 | 1444 | All Jest matchers are [extensively documented here](http://facebook.github.io/jest/docs/en/expect.html). 1445 | Nevertheless you can use a third-party assertion library like [Chai](http://chaijs.com/) if you want to, as described below. 1446 | 1447 | Additionally, you might find [jest-enzyme](https://github.com/blainekasten/enzyme-matchers) helpful to simplify your tests with readable matchers. The above `contains` code can be written more simply with jest-enzyme. 1448 | 1449 | ```js 1450 | expect(wrapper).toContainReact(welcome); 1451 | ``` 1452 | 1453 | To enable this, install `jest-enzyme`: 1454 | 1455 | ```sh 1456 | npm install --save jest-enzyme 1457 | ``` 1458 | 1459 | Alternatively you may use `yarn`: 1460 | 1461 | ```sh 1462 | yarn add jest-enzyme 1463 | ``` 1464 | 1465 | Import it in [`src/setupTests.js`](#initializing-test-environment) to make its matchers available in every test: 1466 | 1467 | ```js 1468 | import 'jest-enzyme'; 1469 | ``` 1470 | 1471 | #### Use `react-testing-library` 1472 | 1473 | As an alternative or companion to `enzyme`, you may consider using `react-testing-library`. [`react-testing-library`](https://github.com/kentcdodds/react-testing-library) is a library for testing React components in a way that resembles the way the components are used by end users. It is well suited for unit, integration, and end-to-end testing of React components and applications. It works more directly with DOM nodes, and therefore it's recommended to use with [`jest-dom`](https://github.com/gnapse/jest-dom) for improved assertions. 1474 | 1475 | To install `react-testing-library` and `jest-dom`, you can run: 1476 | 1477 | ```sh 1478 | npm install --save react-testing-library jest-dom 1479 | ``` 1480 | 1481 | Alternatively you may use `yarn`: 1482 | 1483 | ```sh 1484 | yarn add react-testing-library jest-dom 1485 | ``` 1486 | 1487 | Similar to `enzyme` you can create a `src/setupTests.js` file to avoid boilerplate in your test files: 1488 | 1489 | ```js 1490 | // react-testing-library renders your components to document.body, 1491 | // this will ensure they're removed after each test. 1492 | import 'react-testing-library/cleanup-after-each'; 1493 | 1494 | // this adds jest-dom's custom assertions 1495 | import 'jest-dom/extend-expect'; 1496 | ``` 1497 | 1498 | Here's an example of using `react-testing-library` and `jest-dom` for testing that the `` component renders "Welcome to React". 1499 | 1500 | ```js 1501 | import React from 'react'; 1502 | import { render } from 'react-testing-library'; 1503 | import App from './App'; 1504 | 1505 | it('renders welcome message', () => { 1506 | const { getByText } = render(); 1507 | expect(getByText('Welcome to React')).toBeInTheDocument(); 1508 | }); 1509 | ``` 1510 | 1511 | Learn more about the utilities provided by `react-testing-library` to facilitate testing asynchronous interactions as well as selecting form elements from [the `react-testing-library` documentation](https://github.com/kentcdodds/react-testing-library) and [examples](https://codesandbox.io/s/github/kentcdodds/react-testing-library-examples). 1512 | 1513 | ### Using Third Party Assertion Libraries 1514 | 1515 | We recommend that you use `expect()` for assertions and `jest.fn()` for spies. If you are having issues with them please [file those against Jest](https://github.com/facebook/jest/issues/new), and we’ll fix them. We intend to keep making them better for React, supporting, for example, [pretty-printing React elements as JSX](https://github.com/facebook/jest/pull/1566). 1516 | 1517 | However, if you are used to other libraries, such as [Chai](http://chaijs.com/) and [Sinon](http://sinonjs.org/), or if you have existing code using them that you’d like to port over, you can import them normally like this: 1518 | 1519 | ```js 1520 | import sinon from 'sinon'; 1521 | import { expect } from 'chai'; 1522 | ``` 1523 | 1524 | and then use them in your tests like you normally do. 1525 | 1526 | ### Initializing Test Environment 1527 | 1528 | > Note: this feature is available with `react-scripts@0.4.0` and higher. 1529 | 1530 | If your app uses a browser API that you need to mock in your tests or if you just need a global setup before running your tests, add a `src/setupTests.js` to your project. It will be automatically executed before running your tests. 1531 | 1532 | For example: 1533 | 1534 | #### `src/setupTests.js` 1535 | 1536 | ```js 1537 | const localStorageMock = { 1538 | getItem: jest.fn(), 1539 | setItem: jest.fn(), 1540 | clear: jest.fn(), 1541 | }; 1542 | global.localStorage = localStorageMock; 1543 | ``` 1544 | 1545 | > Note: Keep in mind that if you decide to "eject" before creating `src/setupTests.js`, the resulting `package.json` file won't contain any reference to it, so you should manually create the property `setupTestFrameworkScriptFile` in the configuration for Jest, something like the following: 1546 | 1547 | > ```js 1548 | > "jest": { 1549 | > // ... 1550 | > "setupTestFrameworkScriptFile": "/src/setupTests.js" 1551 | > } 1552 | > ``` 1553 | 1554 | ### Focusing and Excluding Tests 1555 | 1556 | You can replace `it()` with `xit()` to temporarily exclude a test from being executed. 1557 | Similarly, `fit()` lets you focus on a specific test without running any other tests. 1558 | 1559 | ### Coverage Reporting 1560 | 1561 | Jest has an integrated coverage reporter that works well with ES6 and requires no configuration. 1562 | Run `npm test -- --coverage` (note extra `--` in the middle) to include a coverage report like this: 1563 | 1564 |  1565 | 1566 | Note that tests run much slower with coverage so it is recommended to run it separately from your normal workflow. 1567 | 1568 | #### Configuration 1569 | 1570 | The default Jest coverage configuration can be overridden by adding any of the following supported keys to a Jest config in your package.json. 1571 | 1572 | Supported overrides: 1573 | 1574 | - [`collectCoverageFrom`](https://facebook.github.io/jest/docs/en/configuration.html#collectcoveragefrom-array) 1575 | - [`coverageReporters`](https://facebook.github.io/jest/docs/en/configuration.html#coveragereporters-array-string) 1576 | - [`coverageThreshold`](https://facebook.github.io/jest/docs/en/configuration.html#coveragethreshold-object) 1577 | - [`snapshotSerializers`](https://facebook.github.io/jest/docs/en/configuration.html#snapshotserializers-array-string) 1578 | 1579 | Example package.json: 1580 | 1581 | ```json 1582 | { 1583 | "name": "your-package", 1584 | "jest": { 1585 | "collectCoverageFrom": [ 1586 | "src/**/*.{js,jsx}", 1587 | "!/node_modules/", 1588 | "!/path/to/dir/" 1589 | ], 1590 | "coverageThreshold": { 1591 | "global": { 1592 | "branches": 90, 1593 | "functions": 90, 1594 | "lines": 90, 1595 | "statements": 90 1596 | } 1597 | }, 1598 | "coverageReporters": ["text"], 1599 | "snapshotSerializers": ["my-serializer-module"] 1600 | } 1601 | } 1602 | ``` 1603 | 1604 | ### Continuous Integration 1605 | 1606 | By default `npm test` runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called `CI`. 1607 | 1608 | When creating a build of your application with `npm run build` linter warnings are not checked by default. Like `npm test`, you can force the build to perform a linter warning check by setting the environment variable `CI`. If any warnings are encountered then the build fails. 1609 | 1610 | Popular CI servers already set the environment variable `CI` by default but you can do this yourself too: 1611 | 1612 | ### On CI servers 1613 | 1614 | #### Travis CI 1615 | 1616 | 1. Following the [Travis Getting started](https://docs.travis-ci.com/user/getting-started/) guide for syncing your GitHub repository with Travis. You may need to initialize some settings manually in your [profile](https://travis-ci.org/profile) page. 1617 | 1. Add a `.travis.yml` file to your git repository. 1618 | 1619 | ``` 1620 | language: node_js 1621 | node_js: 1622 | - 8 1623 | cache: 1624 | directories: 1625 | - node_modules 1626 | script: 1627 | - npm run build 1628 | - npm test 1629 | ``` 1630 | 1631 | 1. Trigger your first build with a git push. 1632 | 1. [Customize your Travis CI Build](https://docs.travis-ci.com/user/customizing-the-build/) if needed. 1633 | 1634 | #### CircleCI 1635 | 1636 | Follow [this article](https://medium.com/@knowbody/circleci-and-zeits-now-sh-c9b7eebcd3c1) to set up CircleCI with a Create React App project. 1637 | 1638 | ### On your own environment 1639 | 1640 | ##### Windows (cmd.exe) 1641 | 1642 | ```cmd 1643 | set CI=true&&npm test 1644 | ``` 1645 | 1646 | ```cmd 1647 | set CI=true&&npm run build 1648 | ``` 1649 | 1650 | (Note: the lack of whitespace is intentional.) 1651 | 1652 | ##### Windows (Powershell) 1653 | 1654 | ```Powershell 1655 | ($env:CI = $true) -and (npm test) 1656 | ``` 1657 | 1658 | ```Powershell 1659 | ($env:CI = $true) -and (npm run build) 1660 | ``` 1661 | 1662 | ##### Linux, macOS (Bash) 1663 | 1664 | ```bash 1665 | CI=true npm test 1666 | ``` 1667 | 1668 | ```bash 1669 | CI=true npm run build 1670 | ``` 1671 | 1672 | The test command will force Jest to run tests once instead of launching the watcher. 1673 | 1674 | > If you find yourself doing this often in development, please [file an issue](https://github.com/facebook/create-react-app/issues/new) to tell us about your use case because we want to make watcher the best experience and are open to changing how it works to accommodate more workflows. 1675 | 1676 | The build command will check for linter warnings and fail if any are found. 1677 | 1678 | ### Disabling jsdom 1679 | 1680 | If you know that none of your tests depend on [jsdom](https://github.com/tmpvar/jsdom), you can safely set `--env=node`, and your tests will run faster: 1681 | 1682 | ```diff 1683 | "scripts": { 1684 | "start": "react-scripts start", 1685 | "build": "react-scripts build", 1686 | - "test": "react-scripts test" 1687 | + "test": "react-scripts test --env=node" 1688 | ``` 1689 | 1690 | To help you make up your mind, here is a list of APIs that **need jsdom**: 1691 | 1692 | - Any browser globals like `window` and `document` 1693 | - [`ReactDOM.render()`](https://facebook.github.io/react/docs/top-level-api.html#reactdom.render) 1694 | - [`TestUtils.renderIntoDocument()`](https://facebook.github.io/react/docs/test-utils.html#renderintodocument) ([a shortcut](https://github.com/facebook/react/blob/34761cf9a252964abfaab6faf74d473ad95d1f21/src/test/ReactTestUtils.js#L83-L91) for the above) 1695 | - [`mount()`](http://airbnb.io/enzyme/docs/api/mount.html) in [Enzyme](http://airbnb.io/enzyme/index.html) 1696 | 1697 | In contrast, **jsdom is not needed** for the following APIs: 1698 | 1699 | - [`TestUtils.createRenderer()`](https://facebook.github.io/react/docs/test-utils.html#shallow-rendering) (shallow rendering) 1700 | - [`shallow()`](http://airbnb.io/enzyme/docs/api/shallow.html) in [Enzyme](http://airbnb.io/enzyme/index.html) 1701 | 1702 | Finally, jsdom is also not needed for [snapshot testing](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html). 1703 | 1704 | ### Snapshot Testing 1705 | 1706 | Snapshot testing is a feature of Jest that automatically generates text snapshots of your components and saves them on the disk so if the UI output changes, you get notified without manually writing any assertions on the component output. [Read more about snapshot testing.](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html) 1707 | 1708 | ### Editor Integration 1709 | 1710 | If you use [Visual Studio Code](https://code.visualstudio.com), there is a [Jest extension](https://github.com/orta/vscode-jest) which works with Create React App out of the box. This provides a lot of IDE-like features while using a text editor: showing the status of a test run with potential fail messages inline, starting and stopping the watcher automatically, and offering one-click snapshot updates. 1711 | 1712 |  1713 | 1714 | ## Debugging Tests 1715 | 1716 | There are various ways to setup a debugger for your Jest tests. We cover debugging in Chrome and [Visual Studio Code](https://code.visualstudio.com/). 1717 | 1718 | > Note: debugging tests requires Node 8 or higher. 1719 | 1720 | ### Debugging Tests in Chrome 1721 | 1722 | Add the following to the `scripts` section in your project's `package.json` 1723 | 1724 | ```json 1725 | "scripts": { 1726 | "test:debug": "react-scripts --inspect-brk test --runInBand" 1727 | } 1728 | ``` 1729 | 1730 | Place `debugger;` statements in any test and run: 1731 | 1732 | ```bash 1733 | $ npm run test:debug 1734 | ``` 1735 | 1736 | This will start running your Jest tests, but pause before executing to allow a debugger to attach to the process. 1737 | 1738 | Open the following in Chrome 1739 | 1740 | ``` 1741 | about:inspect 1742 | ``` 1743 | 1744 | After opening that link, the Chrome Developer Tools will be displayed. Select `inspect` on your process and a breakpoint will be set at the first line of the react script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack. 1745 | 1746 | > Note: the --runInBand cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time. 1747 | 1748 | ### Debugging Tests in Visual Studio Code 1749 | 1750 | Debugging Jest tests is supported out of the box for [Visual Studio Code](https://code.visualstudio.com). 1751 | 1752 | Use the following [`launch.json`](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) configuration file: 1753 | 1754 | ``` 1755 | { 1756 | "version": "0.2.0", 1757 | "configurations": [ 1758 | { 1759 | "name": "Debug CRA Tests", 1760 | "type": "node", 1761 | "request": "launch", 1762 | "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts", 1763 | "args": [ 1764 | "test", 1765 | "--runInBand", 1766 | "--no-cache" 1767 | ], 1768 | "cwd": "${workspaceRoot}", 1769 | "protocol": "inspector", 1770 | "console": "integratedTerminal", 1771 | "internalConsoleOptions": "neverOpen" 1772 | } 1773 | ] 1774 | } 1775 | ``` 1776 | 1777 | ## Developing Components in Isolation 1778 | 1779 | Usually, in an app, you have a lot of UI components, and each of them has many different states. 1780 | For an example, a simple button component could have following states: 1781 | 1782 | - In a regular state, with a text label. 1783 | - In the disabled mode. 1784 | - In a loading state. 1785 | 1786 | Usually, it’s hard to see these states without running a sample app or some examples. 1787 | 1788 | Create React App doesn’t include any tools for this by default, but you can easily add [Storybook for React](https://storybook.js.org) ([source](https://github.com/storybooks/storybook)) or [React Styleguidist](https://react-styleguidist.js.org/) ([source](https://github.com/styleguidist/react-styleguidist)) to your project. **These are third-party tools that let you develop components and see all their states in isolation from your app**. 1789 | 1790 |  1791 | 1792 | You can also deploy your Storybook or style guide as a static app. This way, everyone in your team can view and review different states of UI components without starting a backend server or creating an account in your app. 1793 | 1794 | ### Getting Started with Storybook 1795 | 1796 | Storybook is a development environment for React UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components. 1797 | 1798 | First, install the following npm package globally: 1799 | 1800 | ```sh 1801 | npm install -g @storybook/cli 1802 | ``` 1803 | 1804 | Then, run the following command inside your app’s directory: 1805 | 1806 | ```sh 1807 | getstorybook 1808 | ``` 1809 | 1810 | After that, follow the instructions on the screen. 1811 | 1812 | Learn more about React Storybook: 1813 | 1814 | - [Learn Storybook (tutorial)](https://learnstorybook.com) 1815 | - [Documentation](https://storybook.js.org/basics/introduction/) 1816 | - [GitHub Repo](https://github.com/storybooks/storybook) 1817 | - [Snapshot Testing UI](https://github.com/storybooks/storybook/tree/master/addons/storyshots) with Storybook + addon/storyshot 1818 | 1819 | ### Getting Started with Styleguidist 1820 | 1821 | Styleguidist combines a style guide, where all your components are presented on a single page with their props documentation and usage examples, with an environment for developing components in isolation, similar to Storybook. In Styleguidist you write examples in Markdown, where each code snippet is rendered as a live editable playground. 1822 | 1823 | First, install Styleguidist: 1824 | 1825 | ```sh 1826 | npm install --save react-styleguidist 1827 | ``` 1828 | 1829 | Alternatively you may use `yarn`: 1830 | 1831 | ```sh 1832 | yarn add react-styleguidist 1833 | ``` 1834 | 1835 | Then, add these scripts to your `package.json`: 1836 | 1837 | ```diff 1838 | "scripts": { 1839 | + "styleguide": "styleguidist server", 1840 | + "styleguide:build": "styleguidist build", 1841 | "start": "react-scripts start", 1842 | ``` 1843 | 1844 | Then, run the following command inside your app’s directory: 1845 | 1846 | ```sh 1847 | npm run styleguide 1848 | ``` 1849 | 1850 | After that, follow the instructions on the screen. 1851 | 1852 | Learn more about React Styleguidist: 1853 | 1854 | - [GitHub Repo](https://github.com/styleguidist/react-styleguidist) 1855 | - [Documentation](https://react-styleguidist.js.org/docs/getting-started.html) 1856 | 1857 | ## Publishing Components to npm 1858 | 1859 | Create React App doesn't provide any built-in functionality to publish a component to npm. If you're ready to extract a component from your project so other people can use it, we recommend moving it to a separate directory outside of your project and then using a tool like [nwb](https://github.com/insin/nwb#react-components-and-libraries) to prepare it for publishing. 1860 | 1861 | ## Making a Progressive Web App 1862 | 1863 | The production build has all the tools necessary to generate a first-class 1864 | [Progressive Web App](https://developers.google.com/web/progressive-web-apps/), 1865 | but **the offline/cache-first behavior is opt-in only**. By default, 1866 | the build process will generate a service worker file, but it will not be 1867 | registered, so it will not take control of your production web app. 1868 | 1869 | In order to opt-in to the offline-first behavior, developers should look for the 1870 | following in their [`src/index.js`](src/index.js) file: 1871 | 1872 | ```js 1873 | // If you want your app to work offline and load faster, you can change 1874 | // unregister() to register() below. Note this comes with some pitfalls. 1875 | // Learn more about service workers: http://bit.ly/CRA-PWA 1876 | serviceWorker.unregister(); 1877 | ``` 1878 | 1879 | As the comment states, switching `serviceWorker.unregister()` to 1880 | `serviceWorker.register()` will opt you in to using the service worker. 1881 | 1882 | ### Why Opt-in? 1883 | 1884 | Offline-first Progressive Web Apps are faster and more reliable than traditional web pages, and provide an engaging mobile experience: 1885 | 1886 | - All static site assets are cached so that your page loads fast on subsequent visits, regardless of network connectivity (such as 2G or 3G). Updates are downloaded in the background. 1887 | - Your app will work regardless of network state, even if offline. This means your users will be able to use your app at 10,000 feet and on the subway. 1888 | - On mobile devices, your app can be added directly to the user's home screen, app icon and all. This eliminates the need for the app store. 1889 | 1890 | However, they [can make debugging deployments more challenging](https://github.com/facebook/create-react-app/issues/2398) so, starting with Create React App 2, service workers are opt-in. 1891 | 1892 | The [`workbox-webpack-plugin`](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin) 1893 | is integrated into production configuration, 1894 | and it will take care of generating a service worker file that will automatically 1895 | precache all of your local assets and keep them up to date as you deploy updates. 1896 | The service worker will use a [cache-first strategy](https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network) 1897 | for handling all requests for local assets, including 1898 | [navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests) 1899 | for your HTML, ensuring that your web app is consistently fast, even on a slow 1900 | or unreliable network. 1901 | 1902 | ### Offline-First Considerations 1903 | 1904 | If you do decide to opt-in to service worker registration, please take the 1905 | following into account: 1906 | 1907 | 1. After the initial caching is done, the [service worker lifecycle](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle) 1908 | controls when updated content ends up being shown to users. In order to guard against 1909 | [race conditions with lazy-loaded content](https://github.com/facebook/create-react-app/issues/3613#issuecomment-353467430), 1910 | the default behavior is to conservatively keep the updated service worker in the "[waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)" 1911 | state. This means that users will end up seeing older content until they close (reloading is not 1912 | enough) their existing, open tabs. See [this blog post](https://jeffy.info/2018/10/10/sw-in-c-r-a.html) 1913 | for more details about this behavior. 1914 | 1915 | 1. Users aren't always familiar with offline-first web apps. It can be useful to 1916 | [let the user know](https://developers.google.com/web/fundamentals/instant-and-offline/offline-ux#inform_the_user_when_the_app_is_ready_for_offline_consumption) 1917 | when the service worker has finished populating your caches (showing a "This web 1918 | app works offline!" message) and also let them know when the service worker has 1919 | fetched the latest updates that will be available the next time they load the 1920 | page (showing a "New content is available once existing tabs are closed." message). Showing 1921 | this messages is currently left as an exercise to the developer, but as a 1922 | starting point, you can make use of the logic included in [`src/serviceWorker.js`](src/serviceWorker.js), which 1923 | demonstrates which service worker lifecycle events to listen for to detect each 1924 | scenario, and which as a default, just logs appropriate messages to the 1925 | JavaScript console. 1926 | 1927 | 1. Service workers [require HTTPS](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers#you_need_https), 1928 | although to facilitate local testing, that policy 1929 | [does not apply to `localhost`](http://stackoverflow.com/questions/34160509/options-for-testing-service-workers-via-http/34161385#34161385). 1930 | If your production web server does not support HTTPS, then the service worker 1931 | registration will fail, but the rest of your web app will remain functional. 1932 | 1933 | 1. The service worker is only enabled in the [production environment](#deployment), 1934 | e.g. the output of `npm run build`. It's recommended that you do not enable an 1935 | offline-first service worker in a development environment, as it can lead to 1936 | frustration when previously cached assets are used and do not include the latest 1937 | changes you've made locally. 1938 | 1939 | 1. If you _need_ to test your offline-first service worker locally, build 1940 | the application (using `npm run build`) and run a simple http server from your 1941 | build directory. After running the build script, `create-react-app` will give 1942 | instructions for one way to test your production build locally and the [deployment instructions](#deployment) have 1943 | instructions for using other methods. _Be sure to always use an 1944 | incognito window to avoid complications with your browser cache._ 1945 | 1946 | 1. By default, the generated service worker file will not intercept or cache any 1947 | cross-origin traffic, like HTTP [API requests](#integrating-with-an-api-backend), 1948 | images, or embeds loaded from a different domain. 1949 | 1950 | ### Progressive Web App Metadata 1951 | 1952 | The default configuration includes a web app manifest located at 1953 | [`public/manifest.json`](public/manifest.json), that you can customize with 1954 | details specific to your web application. 1955 | 1956 | When a user adds a web app to their homescreen using Chrome or Firefox on 1957 | Android, the metadata in [`manifest.json`](public/manifest.json) determines what 1958 | icons, names, and branding colors to use when the web app is displayed. 1959 | [The Web App Manifest guide](https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/) 1960 | provides more context about what each field means, and how your customizations 1961 | will affect your users' experience. 1962 | 1963 | Progressive web apps that have been added to the homescreen will load faster and 1964 | work offline when there's an active service worker. That being said, the 1965 | metadata from the web app manifest will still be used regardless of whether or 1966 | not you opt-in to service worker registration. 1967 | 1968 | ## Analyzing the Bundle Size 1969 | 1970 | [Source map explorer](https://www.npmjs.com/package/source-map-explorer) analyzes 1971 | JavaScript bundles using the source maps. This helps you understand where code 1972 | bloat is coming from. 1973 | 1974 | To add Source map explorer to a Create React App project, follow these steps: 1975 | 1976 | ```sh 1977 | npm install --save source-map-explorer 1978 | ``` 1979 | 1980 | Alternatively you may use `yarn`: 1981 | 1982 | ```sh 1983 | yarn add source-map-explorer 1984 | ``` 1985 | 1986 | Then in `package.json`, add the following line to `scripts`: 1987 | 1988 | ```diff 1989 | "scripts": { 1990 | + "analyze": "source-map-explorer build/static/js/main.*", 1991 | "start": "react-scripts start", 1992 | "build": "react-scripts build", 1993 | "test": "react-scripts test", 1994 | ``` 1995 | 1996 | Then to analyze the bundle run the production build then run the analyze 1997 | script. 1998 | 1999 | ``` 2000 | npm run build 2001 | npm run analyze 2002 | ``` 2003 | 2004 | ## Deployment 2005 | 2006 | `npm run build` creates a `build` directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main..js` are served with the contents of the `/static/js/main..js` file. 2007 | 2008 | ### Static Server 2009 | 2010 | For environments using [Node](https://nodejs.org/), the easiest way to handle this would be to install [serve](https://github.com/zeit/serve) and let it handle the rest: 2011 | 2012 | ```sh 2013 | npm install -g serve 2014 | serve -s build 2015 | ``` 2016 | 2017 | The last command shown above will serve your static site on the port **5000**. Like many of [serve](https://github.com/zeit/serve)’s internal settings, the port can be adjusted using the `-p` or `--port` flags. 2018 | 2019 | Run this command to get a full list of the options available: 2020 | 2021 | ```sh 2022 | serve -h 2023 | ``` 2024 | 2025 | ### Other Solutions 2026 | 2027 | You don’t necessarily need a static server in order to run a Create React App project in production. It works just as fine integrated into an existing dynamic one. 2028 | 2029 | Here’s a programmatic example using [Node](https://nodejs.org/) and [Express](http://expressjs.com/): 2030 | 2031 | ```javascript 2032 | const express = require('express'); 2033 | const path = require('path'); 2034 | const app = express(); 2035 | 2036 | app.use(express.static(path.join(__dirname, 'build'))); 2037 | 2038 | app.get('/', function(req, res) { 2039 | res.sendFile(path.join(__dirname, 'build', 'index.html')); 2040 | }); 2041 | 2042 | app.listen(9000); 2043 | ``` 2044 | 2045 | The choice of your server software isn’t important either. Since Create React App is completely platform-agnostic, there’s no need to explicitly use Node. 2046 | 2047 | The `build` folder with static assets is the only output produced by Create React App. 2048 | 2049 | However this is not quite enough if you use client-side routing. Read the next section if you want to support URLs like `/todos/42` in your single-page app. 2050 | 2051 | ### Serving Apps with Client-Side Routing 2052 | 2053 | If you use routers that use the HTML5 [`pushState` history API](https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries) under the hood (for example, [React Router](https://github.com/ReactTraining/react-router) with `browserHistory`), many static file servers will fail. For example, if you used React Router with a route for `/todos/42`, the development server will respond to `localhost:3000/todos/42` properly, but an Express serving a production build as above will not. 2054 | 2055 | This is because when there is a fresh page load for a `/todos/42`, the server looks for the file `build/todos/42` and does not find it. The server needs to be configured to respond to a request to `/todos/42` by serving `index.html`. For example, we can amend our Express example above to serve `index.html` for any unknown paths: 2056 | 2057 | ```diff 2058 | app.use(express.static(path.join(__dirname, 'build'))); 2059 | 2060 | -app.get('/', function (req, res) { 2061 | +app.get('/*', function (req, res) { 2062 | res.sendFile(path.join(__dirname, 'build', 'index.html')); 2063 | }); 2064 | ``` 2065 | 2066 | If you’re using [Apache HTTP Server](https://httpd.apache.org/), you need to create a `.htaccess` file in the `public` folder that looks like this: 2067 | 2068 | ``` 2069 | Options -MultiViews 2070 | RewriteEngine On 2071 | RewriteCond %{REQUEST_FILENAME} !-f 2072 | RewriteRule ^ index.html [QSA,L] 2073 | ``` 2074 | 2075 | It will get copied to the `build` folder when you run `npm run build`. 2076 | 2077 | If you’re using [Apache Tomcat](http://tomcat.apache.org/), you need to follow [this Stack Overflow answer](https://stackoverflow.com/a/41249464/4878474). 2078 | 2079 | Now requests to `/todos/42` will be handled correctly both in development and in production. 2080 | 2081 | On a production build, and when you've [opted-in](#why-opt-in), 2082 | a [service worker](https://developers.google.com/web/fundamentals/primers/service-workers/) will automatically handle all navigation requests, like for 2083 | `/todos/42`, by serving the cached copy of your `index.html`. This 2084 | service worker navigation routing can be configured or disabled by 2085 | [`eject`ing](#npm-run-eject) and then modifying the 2086 | [`navigateFallback`](https://github.com/GoogleChrome/sw-precache#navigatefallback-string) 2087 | and [`navigateFallbackWhitelist`](https://github.com/GoogleChrome/sw-precache#navigatefallbackwhitelist-arrayregexp) 2088 | options of the `SWPreachePlugin` [configuration](../config/webpack.config.prod.js). 2089 | 2090 | When users install your app to the homescreen of their device the default configuration will make a shortcut to `/index.html`. This may not work for client-side routers which expect the app to be served from `/`. Edit the web app manifest at [`public/manifest.json`](public/manifest.json) and change `start_url` to match the required URL scheme, for example: 2091 | 2092 | ```js 2093 | "start_url": ".", 2094 | ``` 2095 | 2096 | ### Building for Relative Paths 2097 | 2098 | By default, Create React App produces a build assuming your app is hosted at the server root. 2099 | To override this, specify the `homepage` in your `package.json`, for example: 2100 | 2101 | ```js 2102 | "homepage": "http://mywebsite.com/relativepath", 2103 | ``` 2104 | 2105 | This will let Create React App correctly infer the root path to use in the generated HTML file. 2106 | 2107 | **Note**: If you are using `react-router@^4`, you can root ``s using the `basename` prop on any ``. 2108 | More information [here](https://reacttraining.com/react-router/web/api/BrowserRouter/basename-string). 2109 | 2110 | For example: 2111 | 2112 | ```js 2113 | 2114 | // renders 2115 | ``` 2116 | 2117 | #### Serving the Same Build from Different Paths 2118 | 2119 | > Note: this feature is available with `react-scripts@0.9.0` and higher. 2120 | 2121 | If you are not using the HTML5 `pushState` history API or not using client-side routing at all, it is unnecessary to specify the URL from which your app will be served. Instead, you can put this in your `package.json`: 2122 | 2123 | ```js 2124 | "homepage": ".", 2125 | ``` 2126 | 2127 | This will make sure that all the asset paths are relative to `index.html`. You will then be able to move your app from `http://mywebsite.com` to `http://mywebsite.com/relativepath` or even `http://mywebsite.com/relative/path` without having to rebuild it. 2128 | 2129 | ### Customizing Environment Variables for Arbitrary Build Environments 2130 | 2131 | You can create an arbitrary build environment by creating a custom `.env` file and loading it using [env-cmd](https://www.npmjs.com/package/env-cmd). 2132 | 2133 | For example, to create a build environment for a staging environment: 2134 | 2135 | 1. Create a file called `.env.staging` 2136 | 1. Set environment variables as you would any other `.env` file (e.g. `REACT_APP_API_URL=http://api-staging.example.com`) 2137 | 1. Install [env-cmd](https://www.npmjs.com/package/env-cmd) 2138 | ```sh 2139 | $ npm install env-cmd --save 2140 | $ # or 2141 | $ yarn add env-cmd 2142 | ``` 2143 | 1. Add a new script to your `package.json`, building with your new environment: 2144 | ```json 2145 | { 2146 | "scripts": { 2147 | "build:staging": "env-cmd .env.staging npm run build" 2148 | } 2149 | } 2150 | ``` 2151 | 2152 | Now you can run `npm run build:staging` to build with the staging environment config. 2153 | You can specify other environments in the same way. 2154 | 2155 | Variables in `.env.production` will be used as fallback because `NODE_ENV` will always be set to `production` for a build. 2156 | 2157 | ### [Azure](https://azure.microsoft.com/) 2158 | 2159 | See [this](https://medium.com/@to_pe/deploying-create-react-app-on-microsoft-azure-c0f6686a4321) blog post on how to deploy your React app to Microsoft Azure. 2160 | 2161 | See [this](https://medium.com/@strid/host-create-react-app-on-azure-986bc40d5bf2#.pycfnafbg) blog post or [this](https://github.com/ulrikaugustsson/azure-appservice-static) repo for a way to use automatic deployment to Azure App Service. 2162 | 2163 | ### [Firebase](https://firebase.google.com/) 2164 | 2165 | Install the Firebase CLI if you haven’t already by running `npm install -g firebase-tools`. Sign up for a [Firebase account](https://console.firebase.google.com/) and create a new project. Run `firebase login` and login with your previous created Firebase account. 2166 | 2167 | Then run the `firebase init` command from your project’s root. You need to choose the **Hosting: Configure and deploy Firebase Hosting sites** and choose the Firebase project you created in the previous step. You will need to agree with `database.rules.json` being created, choose `build` as the public directory, and also agree to **Configure as a single-page app** by replying with `y`. 2168 | 2169 | ```sh 2170 | === Project Setup 2171 | 2172 | First, let's associate this project directory with a Firebase project. 2173 | You can create multiple project aliases by running firebase use --add, 2174 | but for now we'll just set up a default project. 2175 | 2176 | ? What Firebase project do you want to associate as default? Example app (example-app-fd690) 2177 | 2178 | === Database Setup 2179 | 2180 | Firebase Realtime Database Rules allow you to define how your data should be 2181 | structured and when your data can be read from and written to. 2182 | 2183 | ? What file should be used for Database Rules? database.rules.json 2184 | ✔ Database Rules for example-app-fd690 have been downloaded to database.rules.json. 2185 | Future modifications to database.rules.json will update Database Rules when you run 2186 | firebase deploy. 2187 | 2188 | === Hosting Setup 2189 | 2190 | Your public directory is the folder (relative to your project directory) that 2191 | will contain Hosting assets to uploaded with firebase deploy. If you 2192 | have a build process for your assets, use your build's output directory. 2193 | 2194 | ? What do you want to use as your public directory? build 2195 | ? Configure as a single-page app (rewrite all urls to /index.html)? Yes 2196 | ✔ Wrote build/index.html 2197 | 2198 | i Writing configuration info to firebase.json... 2199 | i Writing project information to .firebaserc... 2200 | 2201 | ✔ Firebase initialization complete! 2202 | ``` 2203 | 2204 | IMPORTANT: you need to set proper HTTP caching headers for `service-worker.js` file in `firebase.json` file or you will not be able to see changes after first deployment ([issue #2440](https://github.com/facebook/create-react-app/issues/2440)). It should be added inside `"hosting"` key like next: 2205 | 2206 | ``` 2207 | { 2208 | "hosting": { 2209 | ... 2210 | "headers": [ 2211 | {"source": "/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}]} 2212 | ] 2213 | ... 2214 | ``` 2215 | 2216 | Now, after you create a production build with `npm run build`, you can deploy it by running `firebase deploy`. 2217 | 2218 | ```sh 2219 | === Deploying to 'example-app-fd690'... 2220 | 2221 | i deploying database, hosting 2222 | ✔ database: rules ready to deploy. 2223 | i hosting: preparing build directory for upload... 2224 | Uploading: [============================== ] 75%✔ hosting: build folder uploaded successfully 2225 | ✔ hosting: 8 files uploaded successfully 2226 | i starting release process (may take several minutes)... 2227 | 2228 | ✔ Deploy complete! 2229 | 2230 | Project Console: https://console.firebase.google.com/project/example-app-fd690/overview 2231 | Hosting URL: https://example-app-fd690.firebaseapp.com 2232 | ``` 2233 | 2234 | For more information see [Add Firebase to your JavaScript Project](https://firebase.google.com/docs/web/setup). 2235 | 2236 | ### [GitHub Pages](https://pages.github.com/) 2237 | 2238 | > Note: this feature is available with `react-scripts@0.2.0` and higher. 2239 | 2240 | #### Step 1: Add `homepage` to `package.json` 2241 | 2242 | **The step below is important!** 2243 | **If you skip it, your app will not deploy correctly.** 2244 | 2245 | Open your `package.json` and add a `homepage` field for your project: 2246 | 2247 | ```json 2248 | "homepage": "https://myusername.github.io/my-app", 2249 | ``` 2250 | 2251 | or for a GitHub user page: 2252 | 2253 | ```json 2254 | "homepage": "https://myusername.github.io", 2255 | ``` 2256 | 2257 | or for a custom domain page: 2258 | 2259 | ```json 2260 | "homepage": "https://mywebsite.com", 2261 | ``` 2262 | 2263 | Create React App uses the `homepage` field to determine the root URL in the built HTML file. 2264 | 2265 | #### Step 2: Install `gh-pages` and add `deploy` to `scripts` in `package.json` 2266 | 2267 | Now, whenever you run `npm run build`, you will see a cheat sheet with instructions on how to deploy to GitHub Pages. 2268 | 2269 | To publish it at [https://myusername.github.io/my-app](https://myusername.github.io/my-app), run: 2270 | 2271 | ```sh 2272 | npm install --save gh-pages 2273 | ``` 2274 | 2275 | Alternatively you may use `yarn`: 2276 | 2277 | ```sh 2278 | yarn add gh-pages 2279 | ``` 2280 | 2281 | Add the following scripts in your `package.json`: 2282 | 2283 | ```diff 2284 | "scripts": { 2285 | + "predeploy": "npm run build", 2286 | + "deploy": "gh-pages -d build", 2287 | "start": "react-scripts start", 2288 | "build": "react-scripts build", 2289 | ``` 2290 | 2291 | The `predeploy` script will run automatically before `deploy` is run. 2292 | 2293 | If you are deploying to a GitHub user page instead of a project page you'll need to make two 2294 | additional modifications: 2295 | 2296 | 1. First, change your repository's source branch to be any branch other than **master**. 2297 | 1. Additionally, tweak your `package.json` scripts to push deployments to **master**: 2298 | 2299 | ```diff 2300 | "scripts": { 2301 | "predeploy": "npm run build", 2302 | - "deploy": "gh-pages -d build", 2303 | + "deploy": "gh-pages -b master -d build", 2304 | ``` 2305 | 2306 | #### Step 3: Deploy the site by running `npm run deploy` 2307 | 2308 | Then run: 2309 | 2310 | ```sh 2311 | npm run deploy 2312 | ``` 2313 | 2314 | #### Step 4: Ensure your project’s settings use `gh-pages` 2315 | 2316 | Finally, make sure **GitHub Pages** option in your GitHub project settings is set to use the `gh-pages` branch: 2317 | 2318 | 2319 | 2320 | #### Step 5: Optionally, configure the domain 2321 | 2322 | You can configure a custom domain with GitHub Pages by adding a `CNAME` file to the `public/` folder. 2323 | 2324 | Your CNAME file should look like this: 2325 | 2326 | ``` 2327 | mywebsite.com 2328 | ``` 2329 | 2330 | #### Notes on client-side routing 2331 | 2332 | GitHub Pages doesn’t support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is because when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions: 2333 | 2334 | - You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://reacttraining.com/react-router/web/api/Router) about different history implementations in React Router. 2335 | - Alternatively, you can use a trick to teach GitHub Pages to handle 404 by redirecting to your `index.html` page with a special redirect parameter. You would need to add a `404.html` file with the redirection code to the `build` folder before deploying your project, and you’ll need to add code handling the redirect parameter to `index.html`. You can find a detailed explanation of this technique [in this guide](https://github.com/rafrex/spa-github-pages). 2336 | 2337 | #### Troubleshooting 2338 | 2339 | ##### "/dev/tty: No such a device or address" 2340 | 2341 | If, when deploying, you get `/dev/tty: No such a device or address` or a similar error, try the following: 2342 | 2343 | 1. Create a new [Personal Access Token](https://github.com/settings/tokens) 2344 | 2. `git remote set-url origin https://:@github.com//` . 2345 | 3. Try `npm run deploy` again 2346 | 2347 | ##### "Cannot read property 'email' of null" 2348 | 2349 | If, when deploying, you get `Cannot read property 'email' of null`, try the following: 2350 | 2351 | 1. `git config --global user.name ''` 2352 | 2. `git config --global user.email ''` 2353 | 3. Try `npm run deploy` again 2354 | 2355 | ### [Heroku](https://www.heroku.com/) 2356 | 2357 | Use the [Heroku Buildpack for Create React App](https://github.com/mars/create-react-app-buildpack). 2358 | You can find instructions in [Deploying React with Zero Configuration](https://blog.heroku.com/deploying-react-with-zero-configuration). 2359 | 2360 | #### Resolving Heroku Deployment Errors 2361 | 2362 | Sometimes `npm run build` works locally but fails during deploy via Heroku. Following are the most common cases. 2363 | 2364 | ##### "Module not found: Error: Cannot resolve 'file' or 'directory'" 2365 | 2366 | If you get something like this: 2367 | 2368 | ``` 2369 | remote: Failed to create a production build. Reason: 2370 | remote: Module not found: Error: Cannot resolve 'file' or 'directory' 2371 | MyDirectory in /tmp/build_1234/src 2372 | ``` 2373 | 2374 | It means you need to ensure that the lettercase of the file or directory you `import` matches the one you see on your filesystem or on GitHub. 2375 | 2376 | This is important because Linux (the operating system used by Heroku) is case sensitive. So `MyDirectory` and `mydirectory` are two distinct directories and thus, even though the project builds locally, the difference in case breaks the `import` statements on Heroku remotes. 2377 | 2378 | ##### "Could not find a required file." 2379 | 2380 | If you exclude or ignore necessary files from the package you will see a error similar this one: 2381 | 2382 | ``` 2383 | remote: Could not find a required file. 2384 | remote: Name: `index.html` 2385 | remote: Searched in: /tmp/build_a2875fc163b209225122d68916f1d4df/public 2386 | remote: 2387 | remote: npm ERR! Linux 3.13.0-105-generic 2388 | remote: npm ERR! argv "/tmp/build_a2875fc163b209225122d68916f1d4df/.heroku/node/bin/node" "/tmp/build_a2875fc163b209225122d68916f1d4df/.heroku/node/bin/npm" "run" "build" 2389 | ``` 2390 | 2391 | In this case, ensure that the file is there with the proper lettercase and that’s not ignored on your local `.gitignore` or `~/.gitignore_global`. 2392 | 2393 | ### [Netlify](https://www.netlify.com/) 2394 | 2395 | **To do a manual deploy to Netlify’s CDN:** 2396 | 2397 | ```sh 2398 | npm install netlify-cli -g 2399 | netlify deploy 2400 | ``` 2401 | 2402 | Choose `build` as the path to deploy. 2403 | 2404 | **To setup continuous delivery:** 2405 | 2406 | With this setup Netlify will build and deploy when you push to git or open a pull request: 2407 | 2408 | 1. [Start a new netlify project](https://app.netlify.com/signup) 2409 | 2. Pick your Git hosting service and select your repository 2410 | 3. Click `Build your site` 2411 | 2412 | **Support for client-side routing:** 2413 | 2414 | To support `pushState`, make sure to create a `public/_redirects` file with the following rewrite rules: 2415 | 2416 | ``` 2417 | /* /index.html 200 2418 | ``` 2419 | 2420 | When you build the project, Create React App will place the `public` folder contents into the build output. 2421 | 2422 | ### [Now](https://zeit.co/now) 2423 | 2424 | Now offers a zero-configuration single-command deployment. You can use `now` to deploy your app for free. 2425 | 2426 | 1. Install the `now` command-line tool either via the recommended [desktop tool](https://zeit.co/download) or via node with `npm install -g now`. 2427 | 2428 | 2. Build your app by running `npm run build`. 2429 | 2430 | 3. Move into the build directory by running `cd build`. 2431 | 2432 | 4. Run `now --name your-project-name` from within the build directory. You will see a **now.sh** URL in your output like this: 2433 | 2434 | ``` 2435 | > Ready! https://your-project-name-tpspyhtdtk.now.sh (copied to clipboard) 2436 | ``` 2437 | 2438 | Paste that URL into your browser when the build is complete, and you will see your deployed app. 2439 | 2440 | Details are available in [this article.](https://zeit.co/blog/unlimited-static) 2441 | 2442 | ### [S3](https://aws.amazon.com/s3) and [CloudFront](https://aws.amazon.com/cloudfront/) 2443 | 2444 | See this [blog post](https://medium.com/@omgwtfmarc/deploying-create-react-app-to-s3-or-cloudfront-48dae4ce0af) on how to deploy your React app to Amazon Web Services S3 and CloudFront. 2445 | 2446 | ### [Surge](https://surge.sh/) 2447 | 2448 | Install the Surge CLI if you haven’t already by running `npm install -g surge`. Run the `surge` command and log in you or create a new account. 2449 | 2450 | When asked about the project path, make sure to specify the `build` folder, for example: 2451 | 2452 | ```sh 2453 | project path: /path/to/project/build 2454 | ``` 2455 | 2456 | Note that in order to support routers that use HTML5 `pushState` API, you may want to rename the `index.html` in your build folder to `200.html` before deploying to Surge. This [ensures that every URL falls back to that file](https://surge.sh/help/adding-a-200-page-for-client-side-routing). 2457 | 2458 | ## Advanced Configuration 2459 | 2460 | You can adjust various development and production settings by setting environment variables in your shell or with [.env](#adding-development-environment-variables-in-env). 2461 | 2462 | | Variable | Development | Production | Usage | 2463 | | :------------------: | :--------------------: | :----------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 2464 | | BROWSER | :white_check_mark: | :x: | By default, Create React App will open the default system browser, favoring Chrome on macOS. Specify a [browser](https://github.com/sindresorhus/opn#app) to override this behavior, or set it to `none` to disable it completely. If you need to customize the way the browser is launched, you can specify a node script instead. Any arguments passed to `npm start` will also be passed to this script, and the url where your app is served will be the last argument. Your script's file name must have the `.js` extension. | 2465 | | HOST | :white_check_mark: | :x: | By default, the development web server binds to `localhost`. You may use this variable to specify a different host. | 2466 | | PORT | :white_check_mark: | :x: | By default, the development web server will attempt to listen on port 3000 or prompt you to attempt the next available port. You may use this variable to specify a different port. | 2467 | | HTTPS | :white_check_mark: | :x: | When set to `true`, Create React App will run the development server in `https` mode. | 2468 | | PUBLIC_URL | :x: | :white_check_mark: | Create React App assumes your application is hosted at the serving web server's root or a subpath as specified in [`package.json` (`homepage`)](#building-for-relative-paths). Normally, Create React App ignores the hostname. You may use this variable to force assets to be referenced verbatim to the url you provide (hostname included). This may be particularly useful when using a CDN to host your application. | 2469 | | CI | :large_orange_diamond: | :white_check_mark: | When set to `true`, Create React App treats warnings as failures in the build. It also makes the test runner non-watching. Most CIs set this flag by default. | 2470 | | REACT_EDITOR | :white_check_mark: | :x: | When an app crashes in development, you will see an error overlay with clickable stack trace. When you click on it, Create React App will try to determine the editor you are using based on currently running processes, and open the relevant source file. You can [send a pull request to detect your editor of choice](https://github.com/facebook/create-react-app/issues/2636). Setting this environment variable overrides the automatic detection. If you do it, make sure your systems [PATH]() environment variable points to your editor’s bin folder. You can also set it to `none` to disable it completely. | 2471 | | CHOKIDAR_USEPOLLING | :white_check_mark: | :x: | When set to `true`, the watcher runs in polling mode, as necessary inside a VM. Use this option if `npm start` isn't detecting changes. | 2472 | | GENERATE_SOURCEMAP | :x: | :white_check_mark: | When set to `false`, source maps are not generated for a production build. This solves OOM issues on some smaller machines. | 2473 | | NODE_PATH | :white_check_mark: | :white_check_mark: | Same as [`NODE_PATH` in Node.js](https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders), but only relative folders are allowed. Can be handy for emulating a monorepo setup by setting `NODE_PATH=src`. | 2474 | | INLINE_RUNTIME_CHUNK | :x: | :white_check_mark: | By default, Create React App will embed the runtime script into `index.html` during the production build. When set to `false`, the script will not be embedded and will be imported as usual. This is normally required when dealing with CSP. | 2475 | 2476 | ## Troubleshooting 2477 | 2478 | ### `npm start` doesn’t detect changes 2479 | 2480 | When you save a file while `npm start` is running, the browser should refresh with the updated code. 2481 | If this doesn’t happen, try one of the following workarounds: 2482 | 2483 | - If your project is in a Dropbox folder, try moving it out. 2484 | - If the watcher doesn’t see a file called `index.js` and you’re referencing it by the folder name, you [need to restart the watcher](https://github.com/facebook/create-react-app/issues/1164) due to a Webpack bug. 2485 | - Some editors like Vim and IntelliJ have a “safe write” feature that currently breaks the watcher. You will need to disable it. Follow the instructions in [“Adjusting Your Text Editor”](https://webpack.js.org/guides/development/#adjusting-your-text-editor). 2486 | - If your project path contains parentheses, try moving the project to a path without them. This is caused by a [Webpack watcher bug](https://github.com/webpack/watchpack/issues/42). 2487 | - On Linux and macOS, you might need to [tweak system settings](https://github.com/webpack/docs/wiki/troubleshooting#not-enough-watchers) to allow more watchers. 2488 | - If the project runs inside a virtual machine such as (a Vagrant provisioned) VirtualBox, create an `.env` file in your project directory if it doesn’t exist, and add `CHOKIDAR_USEPOLLING=true` to it. This ensures that the next time you run `npm start`, the watcher uses the polling mode, as necessary inside a VM. 2489 | 2490 | If none of these solutions help please leave a comment [in this thread](https://github.com/facebook/create-react-app/issues/659). 2491 | 2492 | ### `npm test` hangs or crashes on macOS Sierra 2493 | 2494 | If you run `npm test` and the console gets stuck after printing `react-scripts test` to the console there might be a problem with your [Watchman](https://facebook.github.io/watchman/) installation as described in [facebook/create-react-app#713](https://github.com/facebook/create-react-app/issues/713). 2495 | 2496 | We recommend deleting `node_modules` in your project and running `npm install` (or `yarn` if you use it) first. If it doesn't help, you can try one of the numerous workarounds mentioned in these issues: 2497 | 2498 | - [facebook/jest#1767](https://github.com/facebook/jest/issues/1767) 2499 | - [facebook/watchman#358](https://github.com/facebook/watchman/issues/358) 2500 | - [ember-cli/ember-cli#6259](https://github.com/ember-cli/ember-cli/issues/6259) 2501 | 2502 | It is reported that installing Watchman 4.7.0 or newer fixes the issue. If you use [Homebrew](http://brew.sh/), you can run these commands to update it: 2503 | 2504 | ``` 2505 | watchman shutdown-server 2506 | brew update 2507 | brew reinstall watchman 2508 | ``` 2509 | 2510 | You can find [other installation methods](https://facebook.github.io/watchman/docs/install.html#build-install) on the Watchman documentation page. 2511 | 2512 | If this still doesn’t help, try running `launchctl unload -F ~/Library/LaunchAgents/com.github.facebook.watchman.plist`. 2513 | 2514 | There are also reports that _uninstalling_ Watchman fixes the issue. So if nothing else helps, remove it from your system and try again. 2515 | 2516 | ### `npm run build` exits too early 2517 | 2518 | It is reported that `npm run build` can fail on machines with limited memory and no swap space, which is common in cloud environments. Even with small projects this command can increase RAM usage in your system by hundreds of megabytes, so if you have less than 1 GB of available memory your build is likely to fail with the following message: 2519 | 2520 | > The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process. 2521 | 2522 | If you are completely sure that you didn't terminate the process, consider [adding some swap space](https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04) to the machine you’re building on, or build the project locally. 2523 | 2524 | ### `npm run build` fails on Heroku 2525 | 2526 | This may be a problem with case sensitive filenames. 2527 | Please refer to [this section](#resolving-heroku-deployment-errors). 2528 | 2529 | ### Moment.js locales are missing 2530 | 2531 | If you use a [Moment.js](https://momentjs.com/), you might notice that only the English locale is available by default. This is because the locale files are large, and you probably only need a subset of [all the locales provided by Moment.js](https://momentjs.com/#multiple-locale-support). 2532 | 2533 | To add a specific Moment.js locale to your bundle, you need to import it explicitly. 2534 | For example: 2535 | 2536 | ```js 2537 | import moment from 'moment'; 2538 | import 'moment/locale/fr'; 2539 | ``` 2540 | 2541 | If you are importing multiple locales this way, you can later switch between them by calling `moment.locale()` with the locale name: 2542 | 2543 | ```js 2544 | import moment from 'moment'; 2545 | import 'moment/locale/fr'; 2546 | import 'moment/locale/es'; 2547 | 2548 | // ... 2549 | 2550 | moment.locale('fr'); 2551 | ``` 2552 | 2553 | This will only work for locales that have been explicitly imported before. 2554 | 2555 | ### `npm run build` fails to minify 2556 | 2557 | Before `react-scripts@2.0.0`, this problem was caused by third party `node_modules` using modern JavaScript features because the minifier couldn't handle them during the build. This has been solved by compiling standard modern JavaScript features inside `node_modules` in `react-scripts@2.0.0` and higher. 2558 | 2559 | If you're seeing this error, you're likely using an old version of `react-scripts`. You can either fix it by avoiding a dependency that uses modern syntax, or by upgrading to `react-scripts@>=2.0.0` and following the migration instructions in the changelog. 2560 | 2561 | ## Alternatives to Ejecting 2562 | 2563 | [Ejecting](#npm-run-eject) lets you customize anything, but from that point on you have to maintain the configuration and scripts yourself. This can be daunting if you have many similar projects. In such cases instead of ejecting we recommend to _fork_ `react-scripts` and any other packages you need. [This article](https://auth0.com/blog/how-to-configure-create-react-app/) dives into how to do it in depth. You can find more discussion in [this issue](https://github.com/facebook/create-react-app/issues/682). 2564 | 2565 | ## Something Missing? 2566 | 2567 | If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebook/create-react-app/issues) or [contribute some!](https://github.com/facebook/create-react-app/edit/master/packages/react-scripts/template/README.md) 2568 | --------------------------------------------------------------------------------
20 | {project_task.acceptanceCriteria} 21 |
65 | acceptanceCriteria 66 |