@@ -82,15 +82,13 @@ is the main config file for both Webpack and Webpack Encore:
8282 /*
8383 * ENTRY CONFIG
8484 *
85- * Add 1 entry for each "page" of your app
86- * (including one that's included on every page - e.g. "app")
87- *
8885 * Each entry will result in one JavaScript file (e.g. app.js)
8986 * and one CSS file (e.g. app.css) if your JavaScript imports CSS.
9087 */
9188 .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' )
9492
9593 // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
9694 .splitEntryChunks ()
@@ -112,6 +110,10 @@ is the main config file for both Webpack and Webpack Encore:
112110 // enables hashed filenames (e.g. app.abc123.css)
113111 .enableVersioning (Encore .isProduction ())
114112
113+ .configureBabel ((config ) => {
114+ config .plugins .push (' @babel/plugin-proposal-class-properties' );
115+ })
116+
115117 // enables @babel/preset-env polyfills
116118 .configureBabelPresetEnv ((config ) => {
117119 config .useBuiltIns = ' usage' ;
@@ -124,16 +126,15 @@ is the main config file for both Webpack and Webpack Encore:
124126 // uncomment if you use TypeScript
125127 // .enableTypeScriptLoader()
126128
129+ // uncomment if you use React
130+ // .enableReactPreset()
131+
127132 // uncomment to get integrity="..." attributes on your script & link tags
128133 // requires WebpackEncoreBundle 1.4 or higher
129134 // .enableIntegrityHashes(Encore.isProduction())
130135
131136 // uncomment if you're having problems with a jQuery plugin
132137 // .autoProvidejQuery()
133-
134- // uncomment if you use API Platform Admin (composer require api-admin)
135- // .enableReactPreset()
136- // .addEntry('admin', './assets/admin.js')
137138 ;
138139
139140 module .exports = Encore .getWebpackConfig ();
@@ -154,10 +155,8 @@ Next, open the new ``assets/app.js`` file which contains some JavaScript code
154155 // any CSS you import will output into a single css file (app.css in this case)
155156 import ' ./styles/app.css' ;
156157
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' ;
161160
162161 And the new ``assets/styles/app.css `` file:
163162
@@ -168,7 +167,37 @@ And the new ``assets/styles/app.css`` file:
168167 background-color : lightgray ;
169168 }
170169
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+ 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+
171198You'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.
172201
173202.. caution ::
174203
0 commit comments