Skip to content

Commit

Permalink
docs(config): update ts configuration-languages
Browse files Browse the repository at this point in the history
`import *` not required when `esModuleInterop: true` in `tsconfig.json`.

```json
{
  "devDependencies": {
    "@types/node": "^20.3.1",
    "@types/webpack": "^5.28.1",
    "@types/webpack-dev-server": "^4.7.2",
    "ts-loader": "^9.2.6",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.3",
    "webpack": "^5.88.0",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.7.4"
  }
}
```
  • Loading branch information
piouson committed Jun 23, 2023
1 parent 25f43e3 commit a0cc1f4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/content/configuration/configuration-languages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ and then proceed to write your configuration:
**webpack.config.ts**

```typescript
import * as path from 'path';
import * as webpack from 'webpack';
import path from 'path';
import webpack from 'webpack';
// in case you run into any typescript error when configuring `devServer`
import 'webpack-dev-server';

Expand All @@ -50,6 +50,15 @@ const config: webpack.Configuration = {
export default config;
```

**tsconfig.json**

```json
{
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
```

The above sample assumes version >= 2.7 or newer of TypeScript is used with the new `esModuleInterop` and `allowSyntheticDefaultImports` compiler options in your `tsconfig.json` file.

Note that you'll also need to check your `tsconfig.json` file. If the `module` in `compilerOptions` in `tsconfig.json` is `commonjs`, the setting is complete, else webpack will fail with an error. This occurs because `ts-node` does not support any module syntax other than `commonjs`.
Expand Down

0 comments on commit a0cc1f4

Please sign in to comment.