├── .babelrc
├── .editorconfig
├── .eslintignore
├── .flowconfig
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── example
├── .gitignore
├── README.md
├── package.json
├── public
│ ├── favicon.ico
│ └── index.html
├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ └── store.js
└── yarn.lock
├── flow-typed
└── npm
│ ├── enzyme_v2.3.x.js
│ ├── jest_v17.x.x.js
│ ├── json-predicate-v0.9.x.js
│ ├── react-redux_v4.x.x.js
│ └── redux_v3.x.x.js
├── package.json
├── rollup.config.js
├── src
├── Step.js
├── Step.spec.js
├── Wizard.js
├── Wizard.spec.js
├── actionTypes.js
├── actions.js
├── actions.spec.js
├── index.js
├── match.js
├── match.spec.js
├── reducer.js
├── reducer.spec.js
└── types.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": ["transform-runtime"],
3 | "presets": [
4 | "react",
5 | "es2015",
6 | "stage-2"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 | trim_trailing_whitespace = true
7 | charset = utf-8
8 | indent_style = space
9 | indent_size = 2
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | src/**/*.spec.js
2 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/.*
3 |
4 | [include]
5 | flow-typed/npm/json-predicate.v0.9.x.js
6 | flow-typed/npm/react-redux_v4.x.x.js
7 | flow-typed/npm/redux_v3.x.x.js
8 | flow-typed/npm/enzyme_v2.3.x.js
9 | flow-typed/npm/jest_v17.x.x.js
10 |
11 | [libs]
12 |
13 | [options]
14 | esproposal.class_static_fields=enable
15 | esproposal.class_instance_fields=enable
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src/
2 | test/
3 | example/
4 | .babelrc
5 | .editorconfig
6 | .npmignore
7 | .travis.yml
8 | rollup.config.js
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "6"
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | # [0.2.0](https://github.com/sebinsua/react-redux-wizard/compare/v0.1.1...v0.2.0) (2016-12-12)
7 |
8 |
9 | ### Features
10 |
11 | * **json-predicate:** wrote a json-predicate flowtype definition ([04bb87e](https://github.com/sebinsua/react-redux-wizard/commit/04bb87e))
12 | * **json-predicate|match:** reducer can switch step based on json-predicates ([4914bae](https://github.com/sebinsua/react-redux-wizard/commit/4914bae))
13 |
14 |
15 |
16 |
17 | ## [0.1.1](https://github.com/sebinsua/react-redux-wizard/compare/v0.1.0...v0.1.1) (2016-12-12)
18 |
19 |
20 | ### Bug Fixes
21 |
22 | * **previous:** base previous off a stack ([f7212b5](https://github.com/sebinsua/react-redux-wizard/commit/f7212b5))
23 |
24 |
25 |
26 |
27 | # 0.1.0 (2016-12-12)
28 |
29 |
30 | ### Features
31 |
32 | * **Wizard|Step:** early version of Wizard created ([2bcaa59](https://github.com/sebinsua/react-redux-wizard/commit/2bcaa59))
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `react-redux-wizard` [](https://travis-ci.org/sebinsua/react-redux-wizard) [](https://npmjs.org/package/react-redux-wizard)
2 | > A simple wizard for React.
3 |
4 | This component allows you to represent the flow of a wizard with JSX.
5 |
6 | > **NOTE:** I have not worked on an integration with a React router, so if you require [deep-linking](https://en.wikipedia.org/wiki/Deep_linking) it's not quite ready. It is however completely functional for wizards within modals, and for small sign-up wizards, etc.
7 |
8 | ## Example
9 |
10 | ```js
11 | import React from 'react'
12 | import { Wizard, Step, match } from 'react-redux-wizard'
13 |
14 | const StepOne = ({ name, previous, next }) =>
15 |
20 |
21 | function SomeFormWizard () {
22 | return (
23 |
24 |
25 |
33 |
34 |
35 |
36 | )
37 | }
38 |
39 | export default SomeFormWizard
40 | ```
41 |
42 | ## Install
43 |
44 | ```sh
45 | yarn add react-redux-wizard
46 | ```
47 |
48 | ## API
49 |
50 | ### Reducer
51 |
52 | Your root reducer should use the `reducer` exported by this module against its `wizards` key.
53 |
54 | ### Component
55 |
56 | #### `{...steps}`
57 |
58 | #### ``
59 |
60 | `StepPredicate` is an `Array<{ predicate: JsonPredicate, to: string }>` where `JsonPredicate` [follows the JSON Predicate spec](https://github.com/MalcolmDwyer/json-predicate). `match(string, StepNameToValues)` is just sugar for generating these predicates when given some `Step` names and the associated `values` to check for at a `pathName`.
61 |
62 | We can pass a functions in but we really shouldn't as doing so means that the store can no longer be fully serialized. However, it is possible:
63 |
64 | > `StepFn` has the form `(values: KeyValueObject, wizardState: KeyValueObject) => ?string`
65 | and can be used to pick the next step depending on either the values emitted from a component,
66 | or some of the wizard's internal state.
67 |
68 | #### ` void} next={(values: KeyValueObject) => void} />`
69 |
70 | `` should receive two functions `previous` and `next`.
71 |
72 | `previous` will take zero arguments and go to the previous step,
73 | while `next` expects a `values` key-value object.
74 |
75 | These are different functions from the ones you passed into ``.
76 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-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
15 | npm-debug.log
16 |
--------------------------------------------------------------------------------
/example/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 | - [Installing a Dependency](#installing-a-dependency)
19 | - [Importing a Component](#importing-a-component)
20 | - [Adding a Stylesheet](#adding-a-stylesheet)
21 | - [Post-Processing CSS](#post-processing-css)
22 | - [Adding Images and Fonts](#adding-images-and-fonts)
23 | - [Using the `public` Folder](#using-the-public-folder)
24 | - [Using Global Variables](#using-global-variables)
25 | - [Adding Bootstrap](#adding-bootstrap)
26 | - [Adding Flow](#adding-flow)
27 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
28 | - [Can I Use Decorators?](#can-i-use-decorators)
29 | - [Integrating with a Node Backend](#integrating-with-a-node-backend)
30 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
31 | - [Using HTTPS in Development](#using-https-in-development)
32 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
33 | - [Running Tests](#running-tests)
34 | - [Filename Conventions](#filename-conventions)
35 | - [Command Line Interface](#command-line-interface)
36 | - [Version Control Integration](#version-control-integration)
37 | - [Writing Tests](#writing-tests)
38 | - [Testing Components](#testing-components)
39 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries)
40 | - [Initializing Test Environment](#initializing-test-environment)
41 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests)
42 | - [Coverage Reporting](#coverage-reporting)
43 | - [Continuous Integration](#continuous-integration)
44 | - [Disabling jsdom](#disabling-jsdom)
45 | - [Experimental Snapshot Testing](#experimental-snapshot-testing)
46 | - [Editor Integration](#editor-integration)
47 | - [Developing Components in Isolation](#developing-components-in-isolation)
48 | - [Making a Progressive Web App](#making-a-progressive-web-app)
49 | - [Deployment](#deployment)
50 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
51 | - [Building for Relative Paths](#building-for-relative-paths)
52 | - [Firebase](#firebase)
53 | - [GitHub Pages](#github-pages)
54 | - [Heroku](#heroku)
55 | - [Modulus](#modulus)
56 | - [Netlify](#netlify)
57 | - [Now](#now)
58 | - [S3 and CloudFront](#s3-and-cloudfront)
59 | - [Surge](#surge)
60 | - [Troubleshooting](#troubleshooting)
61 | - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra)
62 | - [`npm run build` silently fails](#npm-run-build-silently-fails)
63 | - [Something Missing?](#something-missing)
64 |
65 | ## Updating to New Releases
66 |
67 | Create React App is divided into two packages:
68 |
69 | * `create-react-app` is a global command-line utility that you use to create new projects.
70 | * `react-scripts` is a development dependency in the generated projects (including this one).
71 |
72 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`.
73 |
74 | 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.
75 |
76 | 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.
77 |
78 | 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.
79 |
80 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
81 |
82 | ## Sending Feedback
83 |
84 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
85 |
86 | ## Folder Structure
87 |
88 | After creation, your project should look like this:
89 |
90 | ```
91 | my-app/
92 | README.md
93 | node_modules/
94 | package.json
95 | public/
96 | index.html
97 | favicon.ico
98 | src/
99 | App.css
100 | App.js
101 | App.test.js
102 | index.css
103 | index.js
104 | logo.svg
105 | ```
106 |
107 | For the project to build, **these files must exist with exact filenames**:
108 |
109 | * `public/index.html` is the page template;
110 | * `src/index.js` is the JavaScript entry point.
111 |
112 | You can delete or rename the other files.
113 |
114 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
115 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them.
116 |
117 | Only files inside `public` can be used from `public/index.html`.
118 | Read instructions below for using assets from JavaScript and HTML.
119 |
120 | You can, however, create more top-level directories.
121 | They will not be included in the production build so you can use them for things like documentation.
122 |
123 | ## Available Scripts
124 |
125 | In the project directory, you can run:
126 |
127 | ### `npm start`
128 |
129 | Runs the app in the development mode.
130 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
131 |
132 | The page will reload if you make edits.
133 | You will also see any lint errors in the console.
134 |
135 | ### `npm test`
136 |
137 | Launches the test runner in the interactive watch mode.
138 | See the section about [running tests](#running-tests) for more information.
139 |
140 | ### `npm run build`
141 |
142 | Builds the app for production to the `build` folder.
143 | It correctly bundles React in production mode and optimizes the build for the best performance.
144 |
145 | The build is minified and the filenames include the hashes.
146 | Your app is ready to be deployed!
147 |
148 | See the section about [deployment](#deployment) for more information.
149 |
150 | ### `npm run eject`
151 |
152 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
153 |
154 | 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.
155 |
156 | 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.
157 |
158 | 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.
159 |
160 | ## Syntax Highlighting in the Editor
161 |
162 | To configure the syntax highlighting in your favorite text editor, head to the [Babel's docs](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered.
163 |
164 | ## Displaying Lint Output in the Editor
165 |
166 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
167 |
168 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
169 |
170 | 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.
171 |
172 | You would need to install an ESLint plugin for your editor first.
173 |
174 | >**A note for Atom `linter-eslint` users**
175 |
176 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked:
177 |
178 | >
179 |
180 | Then add this block to the `package.json` file of your project:
181 |
182 | ```js
183 | {
184 | // ...
185 | "eslintConfig": {
186 | "extends": "react-app"
187 | }
188 | }
189 | ```
190 |
191 | Finally, you will need to install some packages *globally*:
192 |
193 | ```sh
194 | 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
195 | ```
196 |
197 | 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.
198 |
199 | ## Installing a Dependency
200 |
201 | 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`:
202 |
203 | ```
204 | npm install --save
205 | ```
206 |
207 | ## Importing a Component
208 |
209 | This project setup supports ES6 modules thanks to Babel.
210 | 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.
211 |
212 | For example:
213 |
214 | ### `Button.js`
215 |
216 | ```js
217 | import React, { Component } from 'react';
218 |
219 | class Button extends Component {
220 | render() {
221 | // ...
222 | }
223 | }
224 |
225 | export default Button; // Don’t forget to use export default!
226 | ```
227 |
228 | ### `DangerButton.js`
229 |
230 |
231 | ```js
232 | import React, { Component } from 'react';
233 | import Button from './Button'; // Import a component from another file
234 |
235 | class DangerButton extends Component {
236 | render() {
237 | return ;
238 | }
239 | }
240 |
241 | export default DangerButton;
242 | ```
243 |
244 | 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.
245 |
246 | 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'`.
247 |
248 | 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.
249 |
250 | Learn more about ES6 modules:
251 |
252 | * [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)
253 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
254 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
255 |
256 | ## Adding a Stylesheet
257 |
258 | 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**:
259 |
260 | ### `Button.css`
261 |
262 | ```css
263 | .Button {
264 | padding: 20px;
265 | }
266 | ```
267 |
268 | ### `Button.js`
269 |
270 | ```js
271 | import React, { Component } from 'react';
272 | import './Button.css'; // Tell Webpack that Button.js uses these styles
273 |
274 | class Button extends Component {
275 | render() {
276 | // You can use them as regular CSS styles
277 | return ;
278 | }
279 | }
280 | ```
281 |
282 | **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.
283 |
284 | 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.
285 |
286 | 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.
287 |
288 | ## Post-Processing CSS
289 |
290 | 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.
291 |
292 | For example, this:
293 |
294 | ```css
295 | .App {
296 | display: flex;
297 | flex-direction: row;
298 | align-items: center;
299 | }
300 | ```
301 |
302 | becomes this:
303 |
304 | ```css
305 | .App {
306 | display: -webkit-box;
307 | display: -ms-flexbox;
308 | display: flex;
309 | -webkit-box-orient: horizontal;
310 | -webkit-box-direction: normal;
311 | -ms-flex-direction: row;
312 | flex-direction: row;
313 | -webkit-box-align: center;
314 | -ms-flex-align: center;
315 | align-items: center;
316 | }
317 | ```
318 |
319 | There is currently no support for preprocessors such as Less, or for sharing variables across CSS files.
320 |
321 | ## Adding Images and Fonts
322 |
323 | With Webpack, using static assets like images and fonts works similarly to CSS.
324 |
325 | 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.
326 |
327 | Here is an example:
328 |
329 | ```js
330 | import React from 'react';
331 | import logo from './logo.png'; // Tell Webpack this JS file uses this image
332 |
333 | console.log(logo); // /logo.84287d09.png
334 |
335 | function Header() {
336 | // Import result is the URL of your image
337 | return ;
338 | }
339 |
340 | export default Header;
341 | ```
342 |
343 | This ensures that when the project is built, Webpack will correctly move the images into the build folder, and provide us with correct paths.
344 |
345 | This works in CSS too:
346 |
347 | ```css
348 | .Logo {
349 | background-image: url(./logo.png);
350 | }
351 | ```
352 |
353 | 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.
354 |
355 | Please be advised that this is also a custom feature of Webpack.
356 |
357 | **It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images).
358 | An alternative way of handling static assets is described in the next section.
359 |
360 | ## Using the `public` Folder
361 |
362 | >Note: this feature is available with `react-scripts@0.5.0` and higher.
363 |
364 | Normally we encourage you to `import` assets in JavaScript files as described above. This mechanism provides a number of benefits:
365 |
366 | * Scripts and stylesheets get minified and bundled together to avoid extra network requests.
367 | * Missing files cause compilation errors instead of 404 errors for your users.
368 | * Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.
369 |
370 | However there is an **escape hatch** that you can use to add an asset outside of the module system.
371 |
372 | If you put a file into the `public` folder, it will **not** be processed by Webpack. Instead it will be copied into the build folder untouched. To reference assets in the `public` folder, you need to use a special variable called `PUBLIC_URL`.
373 |
374 | Inside `index.html`, you can use it like this:
375 |
376 | ```html
377 |
378 | ```
379 |
380 | Only files inside the `public` folder will be accessible by `%PUBLIC_URL%` prefix. If you need to use a file from `src` or `node_modules`, you’ll have to copy it there to explicitly specify your intention to make this file a part of the build.
381 |
382 | When you run `npm run build`, Create React App will substitute `%PUBLIC_URL%` with a correct absolute path so your project works even if you use client-side routing or host it at a non-root URL.
383 |
384 | In JavaScript code, you can use `process.env.PUBLIC_URL` for similar purposes:
385 |
386 | ```js
387 | render() {
388 | // Note: this is an escape hatch and should be used sparingly!
389 | // Normally we recommend using `import` for getting asset URLs
390 | // as described in “Adding Images and Fonts” above this section.
391 | return ;
392 | }
393 | ```
394 |
395 | Keep in mind the downsides of this approach:
396 |
397 | * None of the files in `public` folder get post-processed or minified.
398 | * Missing files will not be called at compilation time, and will cause 404 errors for your users.
399 | * Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change.
400 |
401 | However, it can be handy for referencing assets like [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest) from HTML, or including small scripts like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code.
402 |
403 | Note that if you add a `