|
| 1 | +Enabling Vue.js (vue-loader) |
| 2 | +============================ |
| 3 | + |
| 4 | +Want to use `Vue.js`_? No problem! First, install Vue and some dependencies: |
| 5 | + |
| 6 | +.. code-block:: terminal |
| 7 | +
|
| 8 | + $ yarn add --dev vue vue-loader vue-template-compiler |
| 9 | +
|
| 10 | +Then, activate the ``vue-loader`` in ``webpack.config.js``: |
| 11 | + |
| 12 | +.. code-block:: diff |
| 13 | +
|
| 14 | + // webpack.config.js |
| 15 | + // ... |
| 16 | +
|
| 17 | + Encore |
| 18 | + // ... |
| 19 | + .addEntry('main', './assets/main.js') |
| 20 | +
|
| 21 | + + .enableVueLoader() |
| 22 | + ; |
| 23 | +
|
| 24 | +That's it! Any ``.vue`` files that you require will be processed correctly. You can |
| 25 | +also configure the `vue-loader options`_ via a callback: |
| 26 | + |
| 27 | +.. code-block:: javascript |
| 28 | +
|
| 29 | + .enableVueLoader(function(options) { |
| 30 | + // https://vue-loader.vuejs.org/en/configurations/advanced.html |
| 31 | +
|
| 32 | + options.preLoaders = { |
| 33 | + js: '/path/to/custom/loader' |
| 34 | + }; |
| 35 | + }); |
| 36 | +
|
| 37 | +Hot Module Replacement (HMR) |
| 38 | +---------------------------- |
| 39 | + |
| 40 | +The ``vue-loader`` supports hot module replacement: just update your code and watch |
| 41 | +your Vue.js app update *without* a browser refresh! To activate it, just use the |
| 42 | +``dev-server`` with the ``--hot`` option: |
| 43 | + |
| 44 | +.. code-block:: terminal |
| 45 | +
|
| 46 | + $ ./node_modules/.bin/encore dev-server --hot |
| 47 | +
|
| 48 | +That's it! Change one of your ``.vue`` files and watch your browser update. But |
| 49 | +note: this does *not* currently work for *style* changes in a ``.vue`` file. Seeing |
| 50 | +updated styles still requires a page refresh. |
| 51 | + |
| 52 | +See :doc:`/frontend/encore/dev-server` for more details. |
| 53 | + |
| 54 | +.. _`babel-preset-react`: https://babeljs.io/docs/plugins/preset-react/ |
| 55 | +.. _`Vue.js`: https://vuejs.org/ |
| 56 | +.. _`vue-loader options`: https://vue-loader.vuejs.org/en/configurations/advanced.html |
0 commit comments