@@ -82,15 +82,13 @@ is the main config file for both Webpack and Webpack Encore:
82
82
/*
83
83
* ENTRY CONFIG
84
84
*
85
- * Add 1 entry for each "page" of your app
86
- * (including one that's included on every page - e.g. "app")
87
- *
88
85
* Each entry will result in one JavaScript file (e.g. app.js)
89
86
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
90
87
*/
91
88
.addEntry (' app' , ' ./assets/app.js' )
92
- // .addEntry('page1', './assets/page1.js')
93
- // .addEntry('page2', './assets/page2.js')
89
+
90
+ // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
91
+ .enableStimulusBridge (' ./assets/controllers.json' )
94
92
95
93
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
96
94
.splitEntryChunks ()
@@ -112,6 +110,10 @@ is the main config file for both Webpack and Webpack Encore:
112
110
// enables hashed filenames (e.g. app.abc123.css)
113
111
.enableVersioning (Encore .isProduction ())
114
112
113
+ .configureBabel ((config ) => {
114
+ config .plugins .push (' @babel/plugin-proposal-class-properties' );
115
+ })
116
+
115
117
// enables @babel/preset-env polyfills
116
118
.configureBabelPresetEnv ((config ) => {
117
119
config .useBuiltIns = ' usage' ;
@@ -124,16 +126,15 @@ is the main config file for both Webpack and Webpack Encore:
124
126
// uncomment if you use TypeScript
125
127
// .enableTypeScriptLoader()
126
128
129
+ // uncomment if you use React
130
+ // .enableReactPreset()
131
+
127
132
// uncomment to get integrity="..." attributes on your script & link tags
128
133
// requires WebpackEncoreBundle 1.4 or higher
129
134
// .enableIntegrityHashes(Encore.isProduction())
130
135
131
136
// uncomment if you're having problems with a jQuery plugin
132
137
// .autoProvidejQuery()
133
-
134
- // uncomment if you use API Platform Admin (composer require api-admin)
135
- // .enableReactPreset()
136
- // .addEntry('admin', './assets/admin.js')
137
138
;
138
139
139
140
module .exports = Encore .getWebpackConfig ();
@@ -154,10 +155,8 @@ Next, open the new ``assets/app.js`` file which contains some JavaScript code
154
155
// any CSS you import will output into a single css file (app.css in this case)
155
156
import ' ./styles/app.css' ;
156
157
157
- // Need jQuery? Install it with "yarn add jquery"(or "npm install jquery"), then uncomment to import it.
158
- // import $ from 'jquery';
159
-
160
- console .log (' Hello Webpack Encore! Edit me in assets/app.js' );
158
+ // start the Stimulus application
159
+ import ' ./bootstrap' ;
161
160
162
161
And the new ``assets/styles/app.css `` file:
163
162
@@ -168,7 +167,37 @@ And the new ``assets/styles/app.css`` file:
168
167
background-color : lightgray ;
169
168
}
170
169
170
+ You should also add an ``assets/bootstrap.js `` file, which initializes Stimulus:
171
+ a system that you'll learn about soon:
172
+
173
+ .. code-block :: javascript
174
+
175
+ // assets/bootstrap.js
176
+ import { startStimulusApp } from ' @symfony/stimulus-bridge' ;
177
+
178
+ // Registers Stimulus controllers from controllers.json and in the controllers/ directory
179
D8ED
+ export const app = startStimulusApp (require .context (
180
+ ' @symfony/stimulus-bridge/lazy-controller-loader!./controllers' ,
181
+ true ,
182
+ / \. (j| t)sx? $ /
183
+ ));
184
+
185
+ // register any custom, 3rd party controllers here
186
+ // app.register('some_controller_name', SomeImportedController);
187
+
188
+ And finally, create an ``assets/controllers.json `` file, which also fits into
189
+ the Stimulus system:
190
+
191
+ ```json
192
+ {
193
+ "controllers": [],
194
+ "entrypoints": []
195
+ }
196
+ ` ``
197
+
171
198
You'll customize and learn more about these files in :doc: `/frontend/encore/simple-example `.
199
+ When you execute Encore, it will ask you to install a few more dependencies based
200
+ on which features of Encore you have enabled.
172
201
173
202
.. caution ::
174
203
0 commit comments