Skip to content

Commit b9cfe08

Browse files
committed
resolves #15575
add npm equivalent of yarn commands in a separate code block.
1 parent 38834b7 commit b9cfe08

10 files changed

+144
-50
lines changed

frontend/encore/advanced-config.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,15 @@ state of the current configuration to build a new one:
103103
When running Encore, both configurations will be built in parallel. If you
104104
prefer to build configs separately, pass the ``--config-name`` option:
105105

106-
.. code-block:: terminal
106+
.. configuration-block::
107107

108-
$ yarn encore dev --config-name firstConfig
108+
.. code-block:: terminal
109+
110+
$ yarn encore dev --config-name firstConfig
111+
112+
.. code-block:: terminal
113+
114+
$ npm run dev -- --config-name firstConfig
109115
110116
Next, define the output directories of each build:
111117

frontend/encore/bootstrap.rst

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ This article explains how to install and integrate the `Bootstrap CSS framework`
55
in your Symfony application using :doc:`Webpack Encore </frontend>`.
66
First, to be able to customize things further, we'll install ``bootstrap``:
77

8-
.. code-block:: terminal
8+
.. configuration-block::
99

10-
$ yarn add bootstrap --dev
10+
.. code-block:: terminal
11+
12+
$ yarn add bootstrap --dev
13+
14+
.. code-block:: terminal
15+
16+
$ npm install bootstrap --save-dev
1117
1218
Importing Bootstrap Styles
1319
--------------------------
@@ -40,10 +46,17 @@ Importing Bootstrap JavaScript
4046
First, install the JavaScript dependencies required by the Bootstrap version
4147
used in your application:
4248

43-
.. code-block:: terminal
49+
.. configuration-block::
50+
51+
.. code-block:: terminal
52+
53+
// jQuery is only required in versions prior to Bootstrap 5
54+
$ yarn add jquery @popperjs/core --dev
55+
56+
.. code-block:: terminal
4457
45-
// jQuery is only required in versions prior to Bootstrap 5
46-
$ yarn add jquery @popperjs/core --dev
58+
// jQuery is only required in versions prior to Bootstrap 5
59+
$ npm install jquery @popperjs/core --save-dev
4760
4861
Now, require bootstrap from any of your JavaScript files:
4962

frontend/encore/dev-server.rst

+16-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ Using webpack-dev-server and HMR
44
While developing, instead of using ``yarn encore dev --watch``, you can use the
55
`webpack-dev-server`_:
66

7-
.. code-block:: terminal
7+
.. configuration-block::
8+
9+
.. code-block:: terminal
10+
11+
$ yarn encore dev-server
12+
13+
.. code-block:: terminal
814
9-
$ yarn encore dev-server
15+
$ npm run dev-server
1016
1117
This builds and serves the front-end assets from a new server. This server runs at
1218
``localhost:8080`` by default, meaning your build assets are available at ``localhost:8080/build``.
@@ -21,9 +27,15 @@ you're done: the paths in your templates will automatically point to the dev ser
2127
The ``dev-server`` command supports all the options defined by `webpack-dev-server`_.
2228
You can set these options via command line options:
2329

24-
.. code-block:: terminal
30+
.. configuration-block::
31+
32+
.. code-block:: terminal
33+
34+
$ yarn encore dev-server --https --port 9000
35+
36+
.. code-block:: terminal
2537
26-
$ yarn encore dev-server --https --port 9000
38+
$ npm run dev-server -- --https --port 9000
2739
2840
You can also set these options using the ``Encore.configureDevServerOptions()``
2941
method in your ``webpack.config.js`` file:

frontend/encore/faq.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ and the built files. Your ``.gitignore`` file should include:
5353
# whatever path you're passing to Encore.setOutputPath()
5454
/public/build
5555
56-
You *should* commit all of your source asset files, ``package.json`` and ``yarn.lock``.
56+
You *should* commit all of your source asset files, ``package.json`` and ``yarn.lock`` or ``package-lock.json``.
5757

5858
My App Lives under a Subdirectory
5959
---------------------------------
@@ -105,8 +105,9 @@ file script tag is rendered automatically.
105105
This dependency was not found: some-module in ./path/to/file.js
106106
---------------------------------------------------------------
107107

108-
Usually, after you install a package via yarn, you can require / import it to use
109-
it. For example, after running ``yarn add respond.js``, you try to require that module:
108+
Usually, after you install a package via yarn or npm, you can require / import
109+
it to use it. For example, after running ``yarn add respond.js`` or ``npm install respond.js``,
110+
you try to require that module:
110111

111112
.. code-block:: javascript
112113

frontend/encore/installation.rst

+18-8
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ Installing Encore in Symfony Applications
1111
Run these commands to install both the PHP and JavaScript dependencies in your
1212
project:
1313

14-
.. code-block:: terminal
14+
.. configuration-block::
1515

16-
$ composer require symfony/webpack-encore-bundle
17-
$ yarn install
16+
.. code-block:: terminal
17+
18+
$ composer require symfony/webpack-encore-bundle
19+
$ yarn install
20+
21+
.. code-block:: terminal
22+
23+
$ composer require symfony/webpack-encore-bundle
24+
$ npm install
1825
1926
If you are using :ref:`Symfony Flex <symfony-flex>`, this will install and enable
2027
the `WebpackEncoreBundle`_, create the ``assets/`` directory, add a
@@ -30,12 +37,15 @@ Installing Encore in non Symfony Applications
3037

3138
Install Encore into your project via Yarn:
3239

33-
.. code-block:: terminal
40+
.. configuration-block::
41+
42+
.. code-block:: terminal
43+
44+
$ yarn add @symfony/webpack-encore --dev
3445
35-
$ yarn add @symfony/webpack-encore --dev
46+
.. code-block:: terminal
3647
37-
# if you prefer npm, run this command instead:
38-
$ npm install @symfony/webpack-encore --save-dev
48+
$ npm install @symfony/webpack-encore --save-dev
3949
4050
This command creates (or modifies) a ``package.json`` file and downloads
4151
dependencies into a ``node_modules/`` directory. Yarn also creates/updates a
@@ -145,7 +155,7 @@ Next, open the new ``assets/js/app.js`` file which contains some JavaScript code
145155
// any CSS you import will output into a single css file (app.css in this case)
146156
import '../css/app.css';
147157
148-
// Need jQuery? Install it with "yarn add jquery", then uncomment to import it.
158+
// Need jQuery? Install it with "yarn add jquery"(or "npm install jquery"), then uncomment to import it.
149159
// import $ from 'jquery';
150160
151161
console.log('Hello Webpack Encore! Edit me in assets/js/app.js');

frontend/encore/postcss.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ Encore, you're done!
2121

2222
Next, download any plugins you want, like ``autoprefixer``:
2323

24-
.. code-block:: terminal
24+
.. configuration-block::
2525

26-
$ yarn add autoprefixer --dev
26+
.. code-block:: terminal
27+
28+
$ yarn add autoprefixer --dev
29+
30+
.. code-block:: terminal
31+
32+
$ npm install autoprefixer --save-dev
2733
2834
Next, create a ``postcss.config.js`` file at the root of your project:
2935

frontend/encore/reactjs.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ Enabling React.js
88

99
Using React? First add some dependencies with Yarn:
1010

11-
.. code-block:: terminal
1211

13-
$ yarn add react react-dom prop-types
12+
.. configuration-block::
13+
14+
.. code-block:: terminal
15+
16+
$ yarn add react react-dom prop-types
17+
18+
.. code-block:: terminal
19+
20+
$ npm install react react-dom prop-types --save
1421
1522
Enable react in your ``webpack.config.js``:
1623

frontend/encore/simple-example.rst

+47-20
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,29 @@ together and - thanks to the first ``app`` argument - output final ``app.js`` an
5959

6060
To build the assets, run:
6161

62-
.. code-block:: terminal
62+
.. configuration-block::
63+
64+
.. code-block:: terminal
65+
66+
# compile assets once
67+
$ yarn encore dev
68+
69+
# or, recompile assets automatically when files change
70+
$ yarn encore dev --watch
71+
72+
# on deploy, create a production build
73+
$ yarn encore production
6374
64-
# compile assets once
65-
$ yarn encore dev
66-
# if you prefer npm, run:
67-
$ npm run dev
75+
.. code-block:: terminal
6876
69-
# or, recompile assets automatically when files change
70-
$ yarn encore dev --watch
71-
# if you prefer npm, run:
72-
$ npm run watch
77+
# compile assets once
78+
$ npm run dev
7379
74-
# on deploy, create a production build
75-
$ yarn encore production
76-
# if you prefer npm, run:
77-
$ npm run build
80+
# or, recompile assets automatically when files change
81+
$ npm run watch
82+
83+
# on deploy, create a production build
84+
$ npm run build
7885
7986
.. note::
8087

@@ -159,9 +166,15 @@ files. First, create a file that exports a function:
159166
160167
We'll use jQuery to print this message on the page. Install it via:
161168

162-
.. code-block:: terminal
169+
.. configuration-block::
170+
171+
.. code-block:: terminal
172+
173+
$ yarn add jquery --dev
174+
175+
.. code-block:: terminal
163176
164-
$ yarn add jquery --dev
177+
$ npm install jquery --save-dev
165178
166179
Great! Use ``require()`` to import ``jquery`` and ``greet.js``:
167180

@@ -251,9 +264,16 @@ Next, use ``addEntry()`` to tell Webpack to read these two new files when it bui
251264
And because you just changed the ``webpack.config.js`` file, make sure to stop
252265
and restart Encore:
253266

254-
.. code-block:: terminal
255267

256-
$ yarn run encore dev --watch
268+
.. configuration-block::
269+
270+
.. code-block:: terminal
271+
272+
$ yarn run encore dev --watch
273+
274+
.. code-block:: terminal
275+
276+
$ npm run watch
257277
258278
Webpack will now output a new ``checkout.js`` file and a new ``account.js`` file
259279
in your build directory. And, if any of those files require/import CSS, Webpack
@@ -320,10 +340,17 @@ Encore. When you do, you'll see an error!
320340
Encore supports many features. But, instead of forcing all of them on you, when
321341
you need a feature, Encore will tell you what you need to install. Run:
322342

323-
.. code-block:: terminal
343+
.. configuration-block::
344+
345+
.. code-block:: terminal
346+
347+
$ yarn add sass-loader@^10.0.0 sass --dev
348+
$ yarn encore dev --watch
349+
350+
.. code-block:: terminal
324351
325-
$ yarn add sass-loader@^10.0.0 sass --dev
326-
$ yarn encore dev --watch
352+
$ npm install sass-loader@^10.0.0 sass --save-dev
353+
$ npm run watch
327354
328355
Your app now supports Sass. Encore also supports LESS and Stylus. See
329356
:doc:`/frontend/encore/css-preprocessors`.

frontend/encore/url-loader.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ generated CSS files.
88
Webpack Encore provides this feature via Webpack's `URL Loader`_ plugin, but
99
it's disabled by default. First, add the URL loader to your project:
1010

11-
.. code-block:: terminal
11+
.. configuration-block::
1212

13-
$ yarn add url-loader --dev
13+
.. code-block:: terminal
14+
15+
$ yarn add url-loader --dev
16+
17+
.. code-block:: terminal
18+
19+
$ npm install url-loader --save-dev
1420
1521
Then enable it in your ``webpack.config.js``:
1622

frontend/encore/vuejs.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ The ``vue-loader`` supports hot module replacement: just update your code and wa
3535
your Vue.js app update *without* a browser refresh! To activate it, use the
3636
``dev-server`` with the ``--hot`` option:
3737

38-
.. code-block:: terminal
38+
.. configuration-block::
3939

40-
$ yarn encore dev-server --hot
40+
.. code-block:: terminal
41+
42+
$ yarn encore dev-server --hot
43+
44+
.. code-block:: terminal
45+
46+
$ npm run dev-server -- --hot
4147
4248
That's it! Change one of your ``.vue`` files and watch your browser update. But
4349
note: this does *not* currently work for *style* changes in a ``.vue`` file. Seeing

0 commit comments

Comments
 (0)