-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Update documentation for TypeScript webpack usage #7550
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
Merged
alexander-akait
merged 3 commits into
webpack:main
from
Vansh5632:docs/typescript-webpack-usage
Feb 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,42 @@ Now lets change the import of `lodash` in our `./index.ts` due to the fact that | |
|
||
T> To make imports do this by default and keep `import _ from 'lodash';` syntax in TypeScript, set `"allowSyntheticDefaultImports" : true` and `"esModuleInterop" : true` in your **tsconfig.json** file. This is related to TypeScript configuration and mentioned in our guide only for your information. | ||
|
||
## Ways to Use TypeScript in `webpack.config.js` | ||
|
||
There are 5 ways to use TypeScript in `webpack.config.js`: | ||
|
||
1. **Using webpack with TypeScript config:** | ||
|
||
```bash | ||
webpack -c ./webpack.config.ts | ||
``` | ||
|
||
(Not all things are supported due to limitations of `rechoir` and `interpret`.) | ||
|
||
2. **Using custom `--import` for Node.js:** | ||
|
||
```bash | ||
NODE_OPTIONS='--import tsx' webpack --disable-interpret -c ./webpack.config.ts | ||
``` | ||
|
||
3. **Using built-in TypeScript module for Node.js v22.7.0 ≥ YOUR NODE.JS VERSION < v23.6.0:** | ||
|
||
```bash | ||
NODE_OPTIONS='--experimental-strip-types' webpack --disable-interpret -c ./webpack.config.ts | ||
``` | ||
|
||
4. **Using built-in TypeScript module for Node.js ≥ v22.6.0:** | ||
|
||
```bash | ||
webpack --disable-interpret -c ./webpack.config.ts | ||
``` | ||
|
||
5. **Using a tsx for Node.js ≥ v22.6.0:** | ||
|
||
```bash | ||
NODE_OPTIONS='--no-experimental-strip-types --import tsx' webpack --disable-interpret -c ./webpack.config.ts | ||
``` | ||
|
||
## Loader | ||
|
||
[`ts-loader`](https://github.com/TypeStrong/ts-loader) | ||
|
@@ -129,6 +165,8 @@ Note that if you're already using [`babel-loader`](https://github.com/babel/babe | |
|
||
To learn more about source maps, see the [development guide](/guides/development). | ||
|
||
To learn more about source maps, see the [development guide](/guides/development). | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it was duplicated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix that might be typical human error sorry for that |
||
To enable source maps, we must configure TypeScript to output inline source maps to our compiled JavaScript files. The following line must be added to our TypeScript configuration: | ||
|
||
**tsconfig.json** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh let's use
.ts
here too to avoid misleading, missing this 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think there are no more add ons if any let me know so i can do them in one commit 😊