-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
xDeSwa
wants to merge
3
commits into
symfony:2.x
Choose a base branch
from
xDeSwa:2.x
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
------------------------------ | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.