|
| 1 | +Enabling TypeScript (ts-loader) |
| 2 | +=============================== |
| 3 | + |
| 4 | +Want to use `TypeScript`_? No problem! First, install the dependencies: |
| 5 | + |
| 6 | +.. code-block:: terminal |
| 7 | +
|
| 8 | + $ yarn add --dev typescript ts-loader |
| 9 | +
|
| 10 | +Then, activate the ``ts-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.ts') |
| 20 | +
|
| 21 | + .enableTypeScriptLoader() |
| 22 | + ; |
| 23 | +
|
| 24 | +That's it! Any ``.ts`` files that you require will be processed correctly. You can |
| 25 | +also configure the `ts-loader options`_ via a callback: |
| 26 | + |
| 27 | +.. code-block:: javascript |
| 28 | +
|
| 29 | + .enableTypeScriptLoader(function (typeScriptConfigOptions) { |
| 30 | + typeScriptConfigOptions.transpileOnly = true; |
| 31 | + typeScriptConfigOptions.configFileName = '/path/to/tsconfig.json'; |
| 32 | + }); |
| 33 | +
|
| 34 | +If React assets are enabled (``.enableReactPreset()``), any ``.tsx`` file will be |
| 35 | +processed as well by ``ts-loader``. |
| 36 | + |
| 37 | +Loader usage can be checked better in its `README`_ documentation. |
| 38 | + |
| 39 | + "Use webpack like normal, including ``webpack --watch`` and ``webpack-dev-server``, |
| 40 | + or through another build system using the Node.js API." |
| 41 | + |
| 42 | + -- Running section of ts-loader documentation |
| 43 | + |
| 44 | +.. _`TypeScript`: https://www.typescriptlang.org/ |
| 45 | +.. _`ts-loader options`: https://github.com/TypeStrong/ts-loader#options |
| 46 | +.. _`README`: https://github.com/TypeStrong/ts-loader#typescript-loader-for-webpack |
0 commit comments