10
10
- [ Bundle configuration] ( #bundle-configuration )
11
11
- [ Shared dependencies] ( #shared-dependencies )
12
12
- [ Asset output directories] ( #asset-output-directories )
13
+ - [ Ideal configuration] ( #ideal-configuration )
13
14
- [ Loaders] ( #loaders )
14
15
- [ CSS] ( #css )
15
16
- [ Less] ( #less )
@@ -234,7 +235,7 @@ webpack:
234
235
webpack:
235
236
output:
236
237
path: ' % kernel .root_dir %/ ../ web'
237
- dump_dir : ' % kernel .root_dir %/ ../ web/ bundles'
238
+ dump_path : ' % kernel .root_dir %/ ../ web/ bundles'
238
239
public_path: ' / '
239
240
```
240
241
@@ -244,6 +245,65 @@ that exists inside the DOCUMENT_ROOT directory.
244
245
For example, if the `output.path` value is `%kernel.root_dir/../web/packed`, the value of `output.public_path` must be
245
246
set to `/packed`.
246
247
248
+ ### Ideal configuration
249
+
250
+ The following configuration requires the following modules to be present in your `node_modules` directory.
251
+
252
+ - webpack-extract-text-plugin
253
+ - style-loader
254
+ - css-loader
255
+ - less-loader
256
+ - url-loader
257
+ - babel-loader
258
+
259
+ Because we' re creating shared chunks of javascript files, you' ll need to include ' ` /compiled/shared.js` ' manually in
260
+ your base template. The same might also be the case for your CSS files, depending on what you include and where you do
261
+ it.
262
+
263
+ config.yml
264
+ ```yaml
265
+ webpack:
266
+ node:
267
+ binary: ' / path/ to/ node'
268
+ node_modules_path: ' % kernel .root_dir %/ ../ node_modules'
269
+ output:
270
+ path: ' % kernel .root_dir %/ ../ web/ compiled'
271
+ dump_path: ' % kernel .root_dir %/ ../ web/ bundles'
272
+ public_path: ' / compiled'
273
+ common_id: ' shared'
274
+ loaders:
275
+ css:
276
+ enabled: true
277
+ all_chunks: true
278
+ filename: ' [name].css '
279
+ less:
280
+ enabled: true
281
+ all_chunks: true
282
+ filename: ' [name].css '
283
+ url:
284
+ enabled: true
285
+ babel:
286
+ enabled: true
287
+ ```
288
+
289
+ base.html.twig
290
+ ```html
291
+ <head>
292
+ <script src="/compiled/shared.js"></script>
293
+ </head>
294
+ ```
295
+
296
+ Somewhere in your twig templates
297
+ ```twig
298
+ {% webpack js "@YourBundle/SomeModule.js" %}
299
+ <script src="{{ asset }}"></script>
300
+ {% endwebpack %}
301
+
302
+ {% webpack css "@YourBundle/SomeModule.js" %}
303
+ <link rel="stylesheet" href="{{ asset }}">
304
+ {% endwebpack %}
305
+ ```
306
+
247
307
## Loaders
248
308
249
309
Loaders allow you to `require` files other than javascript. This package comes with 3 default loaders.
@@ -258,6 +318,8 @@ Each loader has its own configuration under the `loaders` section.
258
318
259
319
Enables loading CSS files.
260
320
321
+ > You need the `css-loader` and `style-loader` node module for this to work.
322
+
261
323
```yaml
262
324
webpack:
263
325
loaders:
@@ -283,6 +345,8 @@ Enables loading less files.
283
345
284
346
This plugin shares the exact same configuration settings as the CSS loader.
285
347
348
+ > You need the `less-loader`, `css-loader` and `style-loader` node modules for this to work.
349
+
286
350
```webpack
287
351
webpack:
288
352
loaders:
@@ -300,10 +364,25 @@ This plugin only has an `enabled` setting. It is disabled by default.
300
364
```yaml
301
365
webpack:
302
366
loaders:
303
- less :
367
+ url :
304
368
enabled: true
305
369
```
306
370
371
+ ### Babel
372
+
373
+ The Babel Loader transpiles ECMAScript 6 code to ECMAScript 5 code, allowing it to run in older browsers. The loader
374
+ compiles `.jsx` files instead of `.js` files, because not all files need to be compiled. Once ES6 hits mainstream, all
375
+ you would need to do is gradually rename your jsx files to js files and everything _should_ still work.
376
+
377
+ > You need the `babel-loader` node module for this to work.
378
+
379
+ ```yaml
380
+ webpack:
381
+ loaders:
382
+ babel:
383
+ enabled: true
384
+ ```
385
+
307
386
## Plugins
308
387
309
388
The webpack-bundle package comes with an easy way to develop and use plugins. A plugin simply writes pieces of code
0 commit comments