14 | To get started, edit src/App.js and save to reload.
15 |
16 |
17 | );
18 | }
19 | }
20 |
21 | export default App;
22 |
--------------------------------------------------------------------------------
/reactjs/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | React App
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/reactjs/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | services:
3 |
4 | ##########################
5 | ### REACTJS ##############
6 | ##########################
7 |
8 | frontend:
9 | image: node:8-alpine
10 | working_dir: /app
11 | labels:
12 | - 'traefik.backend=node'
13 | - 'traefik.port=3000'
14 | - 'traefik.frontend.rule=Host:app.docker.localhost'
15 | expose:
16 | - "3000"
17 | volumes:
18 | - ./reactjs:/app
19 | # By default we tell Docker to copy files inside of ./node_modules
20 | # folder from Docker container into the host machine.
21 | # However if you're experiencing performance issues,
22 | # feel free to uncomment the line below.
23 | # - /app/node_modules
24 | command: sh -c 'npm install && npm run start'
25 |
26 | ##########################
27 | ### DRUPAL ###############
28 | ##########################
29 |
30 | # Here we use almost out of the box docker4drupal configuration.
31 | # So you can refer to their documentation for configuration.
32 | # You can add more containers for memcached, redis, varnish, solr, etc
33 | # using pre-built docker images.
34 | # https://github.com/wodby/docker4drupal/blob/master/docker-compose.yml
35 |
36 | backend_php:
37 | image: wodby/drupal-php:8-1.13
38 | # image: wodby/drupal-php:7.0-2.0.0
39 | environment:
40 | PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S backend_mailhog:1025
41 | # PHP_XDEBUG: 1
42 | # PHP_XDEBUG_DEFAULT_ENABLE: 1
43 | # PHP_XDEBUG_REMOTE_CONNECT_BACK: 0 # This is needed to respect remote.host setting bellow
44 | # PHP_XDEBUG_REMOTE_HOST: "10.254.254.254" # You will also need to 'sudo ifconfig lo0 alias 10.254.254.254'
45 | volumes:
46 | - ./drupal:/var/www/html
47 | # - d4d-unison-sync:/var/www/html:rw # Replace volume to this to use docker-sync for macOS users
48 |
49 | backend_mariadb:
50 | image: wodby/mariadb:10.1-2.0.0
51 | environment:
52 | MYSQL_ROOT_PASSWORD: password
53 | MYSQL_DATABASE: drupal
54 | MYSQL_USER: drupal
55 | MYSQL_PASSWORD: drupal
56 | # command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci # The simple way to override the mariadb config.
57 | # volumes:
58 | # - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
59 | # - /path/to/mariadb/data/on/host:/var/lib/mysql # I want to manage volumes manually.
60 |
61 | backend_nginx:
62 | image: wodby/drupal-nginx:8-1.10-2.0.0
63 | restart: unless-stopped
64 | depends_on:
65 | - backend_php
66 | environment:
67 | NGINX_BACKEND_HOST: backend_php
68 | NGINX_SERVER_ROOT: /var/www/html/web
69 | volumes:
70 | - ./drupal:/var/www/html
71 | labels:
72 | - 'traefik.backend=nginx'
73 | - 'traefik.port=80'
74 | - 'traefik.frontend.rule=Host:drupal.docker.localhost'
75 |
76 | backend_pma:
77 | image: phpmyadmin/phpmyadmin
78 | environment:
79 | PMA_HOST: backend_mariadb
80 | PMA_USER: drupal
81 | PMA_PASSWORD: drupal
82 | PHP_UPLOAD_MAX_FILESIZE: 1G
83 | PHP_MAX_INPUT_VARS: 1G
84 | labels:
85 | - 'traefik.backend=pma'
86 | - 'traefik.port=80'
87 | - 'traefik.frontend.rule=Host:pma.drupal.docker.localhost'
88 |
89 | backend_mailhog:
90 | image: mailhog/mailhog
91 | labels:
92 | - 'traefik.backend=mailhog'
93 | - 'traefik.port=8025'
94 | - 'traefik.frontend.rule=Host:mailhog.drupal.docker.localhost'
95 |
96 | ##########################
97 | ### REVERSE PROXY ########
98 | ##########################
99 |
100 | traefik:
101 | image: traefik
102 | restart: unless-stopped
103 | command: -c /dev/null --web --docker --logLevel=INFO
104 | ports:
105 | - '8000:80'
106 | - '8080:8080'
107 | volumes:
108 | - /var/run/docker.sock:/var/run/docker.sock
109 |
110 | # Docker-sync for macOS users
111 | #volumes:
112 | # d4d-unison-sync:
113 | # external: true
114 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Newer version is available!
2 |
3 | There's a newer version of a boilerplate avaialble at https://github.com/systemseed/drupal_reactjs_boilerplate. It has many more features & server side rendering support.
4 |
5 | # What is this project for?
6 |
7 | It's a really quick start for **LOCAL** development of ReactJS + Drupal 8 applications.
8 |
9 | As the result of configuration, you'll get:
10 | - Working and ready for development ReactJS application
11 | - Working and ready for development Drupal 8 application
12 | - UI to access Drupal database
13 | - UI to access all emails rerouted from php (apart from emails sent through SMTP)
14 |
15 | # Advantages of this project
16 |
17 | - You don't need to have `composer` on `npm` installed locally. Everything is being done though Docker containers.
18 | - You don't depend on versions of `composer` or `npm` installed at dev environments of your team members.
19 | - Docker configuration for Drupal is based on [docker4drupal](http://docker4drupal.org) containers. It provides very good flexibility for Docker-based local development. If you need more containers (i.e. for `memcached`, `redis`, `solr`, etc) - just check out what they offer.
20 | - Drupal configuration is based on [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-project) project which provides best dev experience in working with Drupal through `composer`.
21 | - ReactJS application bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app) - minimal & clean start for ReactJS development.
22 | - Human readable local host names. No more ugly `localhost:PORT` stuff.
23 |
24 | # Dependencies
25 |
26 | All you need to have is [Docker](https://docs.docker.com/engine/installation/) and [Docker Compose](https://docs.docker.com/compose/install/) installed. That's it.
27 |
28 | # Hosts
29 |
30 | At the end of configuration journey you'll get the following hosts available:
31 |
32 | | URL | Name |
33 | | -------------------------------------------- | ------------------- |
34 | | http://app.docker.localhost:8000/ | ReactJS application |
35 | | http://drupal.docker.localhost:8000/ | Drupal 8 |
36 | | http://pma.drupal.docker.localhost:8000/ | PhpMyAdmin |
37 | | http://mailhog.drupal.docker.localhost:8000/ | Mailhog |
38 |
39 | If you want, you can go further and configure `traefik` in `docker-compose.yml` file to get rid of `8000` port.
40 | As well as that, you can add custom hosts to your `/etc/hosts` file (for example, `127.0.0. 1 app.local`), reconfigure `traefik` to use these hosts in `docker-compose.yml` and eventually get beautiful URLs.
41 |
42 | # Getting started
43 |
44 | 1. Download this repo to your local machine:
45 |
46 | ```
47 | git clone git@github.com:spleshka/drupal-reactjs-docker.git
48 | ```
49 |
50 | 2. Bootstrap Docker containers listed in `docker-compose.yml` file:
51 |
52 | ```
53 | docker-compose up -d
54 | ```
55 |
56 | During the process all necessary containers will be downloaded.
57 | As well as that, `npm install` will be invoked to build ReactJS dependencies inside of Docker container.
58 | This process may take 1-2 minutes.
59 | It means that `http://app.docker.localhost:8000/` will not be reachable until that (you'll see nginx error).
60 |
61 | You DON'T need to have `npm` installed locally.
62 |
63 | 3. At this point `./drupal` folder is still empty. Let's get it fixed:
64 |
65 | ```
66 | sudo rm drupal/.gitkeep
67 | docker-compose run backend_php composer create-project drupal-composer/drupal-project:8.x-dev . --stability dev --no-interaction -vvv
68 | ```
69 |
70 | All we do here is downloading Drupal with its dependencies using `backend_php` container.
71 | The installation might take around 5 minutes. No worries, it's expected.
72 | Check out [Drupal Project](https://github.com/drupal-composer/drupal-project) for development guideline.
73 |
74 | You DON'T need to have `composer` installed locally.
75 |
76 | 4. It's all done now! You may try accessing any host listed in the `Hosts` section of this manual.
77 |
78 | 5. As the final step you'd probably want to commit everything to your own repository.
79 | Feel free to drop `.git` folder in the project root and initialize it with your git settings.
80 |
81 | As soon as this is done it's safe to run `git add -A` and commit everything what's been added.
82 | All files which should be ignored by git already specified in proper `.gitignore` files.
83 |
84 | ## Shutting down the environments
85 |
86 | It's **IMPORTANT** to stop Docker containers using `docker-compose stop`.
87 |
88 | Of course there's a possibility to shut the Docker containers down using `docker-compose down`, but it will drop Drupal database.
89 | You can read a little bit more about it [here](https://github.com/wodby/docker4drupal/blob/master/CHANGELOG.md#action-required-before-upgrading).
90 |
91 | ## CLI to work with ReactJS application
92 |
93 | To access all `npm` commands you can simply run shell inside of `frontend` Docker container:
94 |
95 | ```
96 | docker-compose run frontend sh
97 | ```
98 |
99 | Then use `npm` CLI as usual. For example, add a new package:
100 |
101 | ```
102 | npm install lodash --save
103 | ```
104 |
105 | All you'll need to commit is the change to `package.json` file.
106 |
107 | ## CLI to work with Drupal application
108 |
109 | To access all available CLI to manage Drupal, run shell inside of `backend_php` Docker container:
110 |
111 | ```
112 | docker-compose run backend_php sh
113 | ```
114 |
115 | Then run any command you need. It's possible to use `composer`, `drush`, `drupal`.
116 |
117 | If you want to run a single command inside of the container then you don't have to run shell first. Just do it this way:
118 |
119 | ```
120 | docker-compose run backend_php composer require drupal/devel:~1.0
121 | ```
122 |
123 | After that commit resulting `composer.json` and `composer.lock` files.
124 |
125 | Note that Drush and Drupal Console have to be invoked inside of `web` folder, so you'll have to `cd web` first.
126 |
127 | Alternatively, you might use the following command to run `drush` or `drupal` CLI outside of Docker container:
128 |
129 | ```
130 | docker-compose run backend_php drush --root="./web/"
131 | ```
132 |
133 | If this command seems to be too long to type every time, consider adding it to the list of your bash aliases:
134 |
135 | ```
136 | alias dockerdrush=docker-compose run backend_php drush --root="./web/"
137 | ```
138 |
139 | Then you'll be able to do something like this:
140 |
141 | ```
142 | dockerdrush cr
143 | ```
144 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/reactjs/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/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/facebookincubator/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 | - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor)
17 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
18 | - [Changing the Page ``](#changing-the-page-title)
19 | - [Installing a Dependency](#installing-a-dependency)
20 | - [Importing a Component](#importing-a-component)
21 | - [Adding a Stylesheet](#adding-a-stylesheet)
22 | - [Post-Processing CSS](#post-processing-css)
23 | - [Adding Images and Fonts](#adding-images-and-fonts)
24 | - [Using the `public` Folder](#using-the-public-folder)
25 | - [Changing the HTML](#changing-the-html)
26 | - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system)
27 | - [When to Use the `public` Folder](#when-to-use-the-public-folder)
28 | - [Using Global Variables](#using-global-variables)
29 | - [Adding Bootstrap](#adding-bootstrap)
30 | - [Adding Flow](#adding-flow)
31 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
32 | - [Can I Use Decorators?](#can-i-use-decorators)
33 | - [Integrating with an API Backend](#integrating-with-an-api-backend)
34 | - [Node](#node)
35 | - [Ruby on Rails](#ruby-on-rails)
36 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
37 | - [Using HTTPS in Development](#using-https-in-development)
38 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
39 | - [Running Tests](#running-tests)
40 | - [Filename Conventions](#filename-conventions)
41 | - [Command Line Interface](#command-line-interface)
42 | - [Version Control Integration](#version-control-integration)
43 | - [Writing Tests](#writing-tests)
44 | - [Testing Components](#testing-components)
45 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries)
46 | - [Initializing Test Environment](#initializing-test-environment)
47 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests)
48 | - [Coverage Reporting](#coverage-reporting)
49 | - [Continuous Integration](#continuous-integration)
50 | - [Disabling jsdom](#disabling-jsdom)
51 | - [Snapshot Testing](#snapshot-testing)
52 | - [Editor Integration](#editor-integration)
53 | - [Developing Components in Isolation](#developing-components-in-isolation)
54 | - [Making a Progressive Web App](#making-a-progressive-web-app)
55 | - [Deployment](#deployment)
56 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
57 | - [Building for Relative Paths](#building-for-relative-paths)
58 | - [Firebase](#firebase)
59 | - [GitHub Pages](#github-pages)
60 | - [Heroku](#heroku)
61 | - [Modulus](#modulus)
62 | - [Netlify](#netlify)
63 | - [Now](#now)
64 | - [S3 and CloudFront](#s3-and-cloudfront)
65 | - [Surge](#surge)
66 | - [Advanced Configuration](#advanced-configuration)
67 | - [Troubleshooting](#troubleshooting)
68 | - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes)
69 | - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra)
70 | - [`npm run build` silently fails](#npm-run-build-silently-fails)
71 | - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku)
72 | - [Something Missing?](#something-missing)
73 |
74 | ## Updating to New Releases
75 |
76 | Create React App is divided into two packages:
77 |
78 | * `create-react-app` is a global command-line utility that you use to create new projects.
79 | * `react-scripts` is a development dependency in the generated projects (including this one).
80 |
81 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`.
82 |
83 | 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.
84 |
85 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/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.
86 |
87 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes.
88 |
89 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
90 |
91 | ## Sending Feedback
92 |
93 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
94 |
95 | ## Folder Structure
96 |
97 | After creation, your project should look like this:
98 |
99 | ```
100 | my-app/
101 | README.md
102 | node_modules/
103 | package.json
104 | public/
105 | index.html
106 | favicon.ico
107 | src/
108 | App.css
109 | App.js
110 | App.test.js
111 | index.css
112 | index.js
113 | logo.svg
114 | ```
115 |
116 | For the project to build, **these files must exist with exact filenames**:
117 |
118 | * `public/index.html` is the page template;
119 | * `src/index.js` is the JavaScript entry point.
120 |
121 | You can delete or rename the other files.
122 |
123 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
124 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them.
125 |
126 | Only files inside `public` can be used from `public/index.html`.
127 | Read instructions below for using assets from JavaScript and HTML.
128 |
129 | You can, however, create more top-level directories.
130 | They will not be included in the production build so you can use them for things like documentation.
131 |
132 | ## Available Scripts
133 |
134 | In the project directory, you can run:
135 |
136 | ### `npm start`
137 |
138 | Runs the app in the development mode.
139 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
140 |
141 | The page will reload if you make edits.
142 | You will also see any lint errors in the console.
143 |
144 | ### `npm test`
145 |
146 | Launches the test runner in the interactive watch mode.
147 | See the section about [running tests](#running-tests) for more information.
148 |
149 | ### `npm run build`
150 |
151 | Builds the app for production to the `build` folder.
152 | It correctly bundles React in production mode and optimizes the build for the best performance.
153 |
154 | The build is minified and the filenames include the hashes.
155 | Your app is ready to be deployed!
156 |
157 | See the section about [deployment](#deployment) for more information.
158 |
159 | ### `npm run eject`
160 |
161 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
162 |
163 | 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.
164 |
165 | 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.
166 |
167 | 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.
168 |
169 | ## Syntax Highlighting in the Editor
170 |
171 | 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.
172 |
173 | ## Displaying Lint Output in the Editor
174 |
175 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
176 |
177 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
178 |
179 | 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.
180 |
181 | You would need to install an ESLint plugin for your editor first.
182 |
183 | >**A note for Atom `linter-eslint` users**
184 |
185 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked:
186 |
187 | >
188 |
189 |
190 | >**For Visual Studio Code users**
191 |
192 | >VS Code ESLint plugin automatically detects Create React App's configuration file. So you do not need to create `eslintrc.json` at the root directory, except when you want to add your own rules. In that case, you should include CRA's config by adding this line:
193 |
194 | >```js
195 | {
196 | // ...
197 | "extends": "react-app"
198 | }
199 | ```
200 |
201 | Then add this block to the `package.json` file of your project:
202 |
203 | ```js
204 | {
205 | // ...
206 | "eslintConfig": {
207 | "extends": "react-app"
208 | }
209 | }
210 | ```
211 |
212 | Finally, you will need to install some packages *globally*:
213 |
214 | ```sh
215 | npm install -g eslint-config-react-app@0.3.0 eslint@3.8.1 babel-eslint@7.0.0 eslint-plugin-react@6.4.1 eslint-plugin-import@2.0.1 eslint-plugin-jsx-a11y@2.2.3 eslint-plugin-flowtype@2.21.0
216 | ```
217 |
218 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months.
219 |
220 | ## Changing the Page ``
221 |
222 | 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.
223 |
224 | 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.
225 |
226 | 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.
227 |
228 | Finally, 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).
229 |
230 | ## Installing a Dependency
231 |
232 | 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`:
233 |
234 | ```
235 | npm install --save
236 | ```
237 |
238 | ## Importing a Component
239 |
240 | This project setup supports ES6 modules thanks to Babel.
241 | 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.
242 |
243 | For example:
244 |
245 | ### `Button.js`
246 |
247 | ```js
248 | import React, { Component } from 'react';
249 |
250 | class Button extends Component {
251 | render() {
252 | // ...
253 | }
254 | }
255 |
256 | export default Button; // Don’t forget to use export default!
257 | ```
258 |
259 | ### `DangerButton.js`
260 |
261 |
262 | ```js
263 | import React, { Component } from 'react';
264 | import Button from './Button'; // Import a component from another file
265 |
266 | class DangerButton extends Component {
267 | render() {
268 | return ;
269 | }
270 | }
271 |
272 | export default DangerButton;
273 | ```
274 |
275 | 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.
276 |
277 | 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'`.
278 |
279 | 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.
280 |
281 | Learn more about ES6 modules:
282 |
283 | * [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)
284 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
285 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
286 |
287 | ## Adding a Stylesheet
288 |
289 | This project setup uses [Webpack](https://webpack.github.io/) 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**:
290 |
291 | ### `Button.css`
292 |
293 | ```css
294 | .Button {
295 | padding: 20px;
296 | }
297 | ```
298 |
299 | ### `Button.js`
300 |
301 | ```js
302 | import React, { Component } from 'react';
303 | import './Button.css'; // Tell Webpack that Button.js uses these styles
304 |
305 | class Button extends Component {
306 | render() {
307 | // You can use them as regular CSS styles
308 | return ;
309 | }
310 | }
311 | ```
312 |
313 | **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-ui-engineering/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.
314 |
315 | 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.
316 |
317 | 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.
318 |
319 | ## Post-Processing CSS
320 |
321 | 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.
322 |
323 | For example, this:
324 |
325 | ```css
326 | .App {
327 | display: flex;
328 | flex-direction: row;
329 | align-items: center;
330 | }
331 | ```
332 |
333 | becomes this:
334 |
335 | ```css
336 | .App {
337 | display: -webkit-box;
338 | display: -ms-flexbox;
339 | display: flex;
340 | -webkit-box-orient: horizontal;
341 | -webkit-box-direction: normal;
342 | -ms-flex-direction: row;
343 | flex-direction: row;
344 | -webkit-box-align: center;
345 | -ms-flex-align: center;
346 | align-items: center;
347 | }
348 | ```
349 |
350 | There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
351 |
352 | ## Adding Images and Fonts
353 |
354 | With Webpack, using static assets like images and fonts works similarly to CSS.
355 |
356 | You can **`import` an image right in a JavaScript module**. This tells Webpack to include that image in the bundle. Unlike CSS imports, importing an image or a font gives you a string value. This value is the final image path you can reference in your code.
357 |
358 | Here is an example:
359 |
360 | ```js
361 | import React from 'react';
362 | import logo from './logo.png'; // Tell Webpack this JS file uses this image
363 |
364 | console.log(logo); // /logo.84287d09.png
365 |
366 | function Header() {
367 | // Import result is the URL of your image
368 | return ;
369 | }
370 |
371 | export default Header;
372 | ```
373 |
374 | This ensures that when the project is built, Webpack will correctly move the images into the build folder, and provide us with correct paths.
375 |
376 | This works in CSS too:
377 |
378 | ```css
379 | .Logo {
380 | background-image: url(./logo.png);
381 | }
382 | ```
383 |
384 | 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.
385 |
386 | Please be advised that this is also a custom feature of Webpack.
387 |
388 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).
389 | An alternative way of handling static assets is described in the next section.
390 |
391 | ## Using the `public` Folder
392 |
393 | >Note: this feature is available with `react-scripts@0.5.0` and higher.
394 |
395 | ### Changing the HTML
396 |
397 | The `public` folder contains the HTML file so you can tweak it, for example, to [set the page title](#changing-the-page-title).
398 | The `