Skip to content

Add typescript loader documentation #8136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Adding more Features
* :doc:`Enabling Vue.js (vue-loader) </frontend/encore/vuejs>`
* :doc:`Configuring Babel </frontend/encore/babel>`
* :doc:`Source maps </frontend/encore/sourcemaps>`
* :doc:`Enabling TypeScript (ts-loader) </frontend/encore/typescript>`

Optimizing
..........
Expand Down
46 changes: 46 additions & 0 deletions frontend/encore/typescript.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Enabling TypeScript (ts-loader)
===============================

Want to use `TypeScript`_? No problem! First, install the dependencies:

.. code-block:: terminal

$ yarn add --dev typescript ts-loader

Then, activate the ``ts-loader`` in ``webpack.config.js``:

.. code-block:: diff

// webpack.config.js
// ...

Encore
// ...
.addEntry('main', './assets/main.ts')

.enableTypeScriptLoader()
;

That's it! Any ``.ts`` files that you require will be processed correctly. You can
also configure the `ts-loader options`_ via a callback:

.. code-block:: javascript

.enableTypeScriptLoader(function (typeScriptConfigOptions) {
typeScriptConfigOptions.transpileOnly = true;
typeScriptConfigOptions.configFileName = '/path/to/tsconfig.json';
});

If React assets are enabled (``.enableReactPreset()``), any ``.tsx`` file will be
processed as well by ``ts-loader``.

Loader usage can be checked better in its `README`_ documentation.

"Use webpack like normal, including ``webpack --watch`` and ``webpack-dev-server``,
or through another build system using the Node.js API."

-- Running section of ts-loader documentation

.. _`TypeScript`: https://www.typescriptlang.org/
.. _`ts-loader options`: https://github.com/TypeStrong/ts-loader#options
.. _`README`: https://github.com/TypeStrong/ts-loader#typescript-loader-for-webpack