@@ -4,8 +4,8 @@ Encore: Setting up your Project
4
4
After :doc: `installing Encore </frontend/encore/installation >`, your app already has one
5
5
CSS and one JS file, organized into an ``assets/ `` directory:
6
6
7
- * ``assets/js/ app.js ``
8
- * ``assets/css /app.css ``
7
+ * ``assets/app.js ``
8
+ * ``assets/styles /app.css ``
9
9
10
10
With Encore, think of your ``app.js `` file like a standalone JavaScript
11
11
application: it will *require * all of the dependencies it needs (e.g. jQuery or React),
@@ -14,7 +14,7 @@ application: it will *require* all of the dependencies it needs (e.g. jQuery or
14
14
15
15
.. code-block :: javascript
16
16
17
- // assets/js/ app.js
17
+ // assets/app.js
18
18
// ...
19
19
20
20
import ' ../css/app.css' ;
@@ -43,14 +43,14 @@ of your project. It already holds the basic config you need:
43
43
// public path used by the web server to access the output path
44
44
.setPublicPath (' /build' )
45
45
46
- .addEntry (' app' , ' ./assets/js/ app.js' )
46
+ .addEntry (' app' , ' ./assets/app.js' )
47
47
48
48
// ...
49
49
;
50
50
51
51
// ...
52
52
53
- The *key * part is ``addEntry() ``: this tells Encore to load the ``assets/js/ app.js ``
53
+ The *key * part is ``addEntry() ``: this tells Encore to load the ``assets/app.js ``
54
54
file and follow *all * of the ``require() `` statements. It will then package everything
55
55
together and - thanks to the first ``app `` argument - output final ``app.js `` and
56
56
``app.css `` files into the ``public/build `` directory.
@@ -115,7 +115,7 @@ can do most of the work for you:
115
115
.. _encore-entrypointsjson-simple-description :
116
116
117
117
That's it! When you refresh your page, all of the JavaScript from
118
- ``assets/js/ app.js `` - as well as any other JavaScript files it included - will
118
+ ``assets/app.js `` - as well as any other JavaScript files it included - will
119
119
be executed. All the CSS files that were required will also be displayed.
120
120
121
121
The ``encore_entry_link_tags() `` and ``encore_entry_script_tags() `` functions
@@ -143,7 +143,7 @@ files. First, create a file that exports a function:
143
143
144
144
.. code-block :: javascript
145
145
146
- // assets/js/ greet.js
146
+ // assets/greet.js
147
147
module .exports = function (name ) {
148
148
return ` Yo yo ${ name} - welcome to Encore!` ;
149
149
};
@@ -158,7 +158,7 @@ Great! Use ``require()`` to import ``jquery`` and ``greet.js``:
158
158
159
159
.. code-block :: diff
160
160
161
- // assets/js/ app.js
161
+ // assets/app.js
162
162
// ...
163
163
164
164
+ // loads the jquery package from node_modules
@@ -187,7 +187,7 @@ To export values using the alternate syntax, use ``export``:
187
187
188
188
.. code-block :: diff
189
189
190
- // assets/js/ greet.js
190
+ // assets/greet.js
191
191
- module.exports = function(name) {
192
192
+ export default function(name) {
193
193
return `Yo yo ${name} - welcome to Encore!`;
@@ -197,7 +197,7 @@ To import values, use ``import``:
197
197
198
198
.. code-block :: diff
199
199
200
- // assets/js/ app.js
200
+ // assets/app.js
201
201
- require('../css/app.css');
202
202
+ import '../css/app.css';
203
203
@@ -219,12 +219,12 @@ etc.). To handle this, create a new "entry" JavaScript file for each page:
219
219
220
220
.. code-block :: javascript
221
221
222
- // assets/js/ checkout.js
222
+ // assets/checkout.js
223
223
// custom code for your checkout page
224
224
225
225
.. code-block :: javascript
226
226
227
- // assets/js/ account.js
227
+ // assets/account.js
228
228
// custom code for your account page
229
229
230
230
Next, use ``addEntry() `` to tell Webpack to read these two new files when it builds:
@@ -234,9 +234,9 @@ Next, use ``addEntry()`` to tell Webpack to read these two new files when it bui
234
234
// webpack.config.js
235
235
Encore
236
236
// ...
237
- .addEntry('app', './assets/js/ app.js')
238
- + .addEntry('checkout', './assets/js/ checkout.js')
239
- + .addEntry('account', './assets/js/ account.js')
237
+ .addEntry('app', './assets/app.js')
238
+ + .addEntry('checkout', './assets/checkout.js')
239
+ + .addEntry('account', './assets/account.js')
240
240
// ...
241
241
242
242
And because you just changed the ``webpack.config.js `` file, make sure to stop
@@ -285,7 +285,7 @@ file to ``app.scss`` and update the ``import`` statement:
285
285
286
286
.. code-block :: diff
287
287
288
- // assets/js/ app.js
288
+ // assets/app.js
289
289
- import '../css/app.css';
290
290
+ import '../css/app.scss';
291
291
@@ -336,7 +336,7 @@ If you want to only compile a CSS file, that's possible via ``addStyleEntry()``:
336
336
Encore
337
337
// ...
338
338
339
- .addStyleEntry (' some_page' , ' ./assets/css /some_page.css' )
339
+ .addStyleEntry (' some_page' , ' ./assets/styles /some_page.css' )
340
340
;
341
341
342
342
This will output a new ``some_page.css ``.
0 commit comments