Skip to content

Commit

Permalink
Rearrange version-specific prod instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterKale committed Mar 1, 2021
1 parent 731124c commit 30ec03c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,23 @@ React assets will be included with the other static assets in the `settings.STAT

Similar to the `bundle_js` template variable mentioned earlier, **django-cra-helper** includes numerous other template variables when the CRA liveserver is _not_ running:

<details>
<summary>For older projects using <strong>react-scripts@&lt;=2.1.8</strong></summary>
<details open>
<summary>For projects using <strong>react-scripts@&gt;=3.2.0</strong></summary>

The two most important variables are `main_js` and `main_css`. These can be injected into the page via a typical call to `{% static %}` in the template:
Starting with `[email protected]`, a new `entrypoints` property can be found in **asset-manifest.json**. This contains an array of files that **django-cra-helper** makes available in templates to more easily inject these files via new `entrypoints.css` and `entrypoints.js` arrays. These **replace** the `main_css` and `main_js` values used above:

```html
{% if main_css %}
<link href="{% static main_css %}" rel="stylesheet">
{% endif %}
{% for file in entrypoints.css %}
<link href="{% static file %}" rel="stylesheet">
{% endfor %}
```
```html
{% if main_js %}
<script type="text/javascript" src="{% static main_js %}"></script>
{% endif %}
{% for file in entrypoints.js %}
<script type="text/javascript" src="{% static file %}"></script>
{% endfor %}
```

> NOTE: Recent attempts at building a fresh CRA project with `[email protected]` were unsuccessful in recreating SPAs that allowed for just a single `main_js`. `npm run build`-produced artifacts functioned almost identically to artifacts generated the same as `[email protected]`, detailed below.
>
> There may be child dependencies of `react-scripts` that make it no longer possible to start apps that will function with the above instructions. In these cases, please try the instructions in the next section.
> NOTE: These JavaScript and CSS files should be arranged in an order required for the site to load; the ultimate order is derived from the order present in **asset-manifest.json**.
</details>
<details>
Expand All @@ -223,22 +221,24 @@ Similar to the `bundle_js` template variable mentioned earlier, **django-cra-hel
</details>

<details>
<summary>For projects using <strong>react-scripts@&gt;=3.2.0</strong></summary>
<summary>For older projects using <strong>react-scripts@&lt;=2.1.8</strong></summary>

Starting with `[email protected]`, a new `entrypoints` property can be found in **asset-manifest.json**. This contains an array of files that **django-cra-helper** makes available in templates to more easily inject these files via new `entrypoints.css` and `entrypoints.js` arrays. These **replace** the `main_css` and `main_js` values used above:
The two most important variables are `main_js` and `main_css`. These can be injected into the page via a typical call to `{% static %}` in the template:

```html
{% for file in entrypoints.css %}
<link href="{% static file %}" rel="stylesheet">
{% endfor %}
{% if main_css %}
<link href="{% static main_css %}" rel="stylesheet">
{% endif %}
```
```html
{% for file in entrypoints.js %}
<script type="text/javascript" src="{% static file %}"></script>
{% endfor %}
{% if main_js %}
<script type="text/javascript" src="{% static main_js %}"></script>
{% endif %}
```

> NOTE: These JavaScript and CSS files should be arranged in an order required for the site to load; the ultimate order is derived from the order present in **asset-manifest.json**.
> NOTE: Recent attempts at building a fresh CRA project with `[email protected]` were unsuccessful in recreating SPAs that allowed for just a single `main_js`. `npm run build`-produced artifacts functioned almost identically to artifacts generated the same as `[email protected]`, detailed below.
>
> There may be child dependencies of `react-scripts` that make it no longer possible to start apps that will function with the above instructions. In these cases, please try the instructions in the next section.
</details>
### Supporting CRA's relative paths
Expand Down

0 comments on commit 30ec03c

Please sign in to comment.