Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.rst Usage React with AssetMapper #1941

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions src/React/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,38 @@ Using with AssetMapper
Because the JSX format isn't pure JavaScript, using this library with AssetMapper
requires some extra steps.

#. Compile your ``.jsx`` files to pure JavaScript files. This can be done by
.. note::

Compile your ``.jsx`` files to pure JavaScript files. This can be done by
installing Babel and the ``@babel/preset-react`` preset. Example:
https://github.com/symfony/ux/blob/2.x/ux.symfony.com/package.json

#. Point this library at the "built" controllers directory that contains the final
1- Create package.json in your project. This file is not included in the **Standard package**. (code below)

.. code-block:: json-object

{
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/preset-react": "^7.18.6",
"svelte": "^3.59.1"
},
"license": "MIT",
"private": true,
"scripts": {
"build": "yarn build-react && yarn build-svelte",
"build-react": "babel assets/react --out-dir assets/build/react --presets=@babel/preset-react",
"build-svelte": "node bin/compile_svelte.js"
}
}

Comment on lines +107 to +126
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to add the content of the package.json. Let's stay simple and say that we need a package.json and to install few dependencies.

2- Point this library at the "built" controllers directory that contains the final
JavaScript files:

.. code-block:: yaml

# config/packages/react.yaml
# config/packages/asset_mapper.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the file name ?

react:
controllers_path: '%kernel.project_dir%/assets/build/react/controllers'

Expand All @@ -119,6 +141,33 @@ Also, inside of your ``.jsx`` files, when importing another component, use the
// use PackageList.js even though the file is named PackageList.jsx
import PackageList from '../components/PackageList.js';

3- Install the required Node.js packages

.. code-block:: terminal

$ npm install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use npm and below yarn. Let's stay on yarn


4- The Flex recipe will have already added the registerReactControllerComponents() code to your assets/app.js file:

.. code-block:: javascript

// assets/app.js
import { registerReactControllerComponents } from '@symfony/ux-react';

registerReactControllerComponents();

.. note::

Do not use **require.context** parameter. Not working with AssetMapper

5- Finally, run the 'build' command below so that we can use the React components you wrote or installed.

.. code-block:: terminal

$ yarn build-react

Dont forget run **php bin/console asset-map:compile** command before deploy.

Backward Compatibility promise
------------------------------

Expand Down