Skip to content

Commit 3c80898

Browse files
fix: ensure TsconfigPathsPlugin is only added if tsconfig.json exists (#643)
1 parent cd49b15 commit 3c80898

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

config/webpack.common.config.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs');
12
const path = require('path');
23
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
34
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
@@ -12,6 +13,14 @@ const {
1213
const paragonThemeCss = getParagonThemeCss(process.cwd());
1314
const brandThemeCss = getParagonThemeCss(process.cwd(), { isBrandOverride: true });
1415

16+
const tsconfigPath = path.resolve(process.cwd(), 'tsconfig.json');
17+
const resolvePlugins = [];
18+
19+
// Conditionally add TsconfigPathsPlugin if tsconfig.json exists
20+
if (fs.existsSync(tsconfigPath)) {
21+
resolvePlugins.push(new TsconfigPathsPlugin({ configFile: tsconfigPath }));
22+
}
23+
1524
module.exports = {
1625
entry: {
1726
app: path.resolve(process.cwd(), './src/index'),
@@ -46,9 +55,7 @@ module.exports = {
4655
'env.config': false,
4756
},
4857
extensions: ['.js', '.jsx', '.ts', '.tsx'],
49-
plugins: [
50-
new TsconfigPathsPlugin(),
51-
],
58+
plugins: resolvePlugins,
5259
},
5360
optimization: {
5461
splitChunks: {

example/src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StrictMode } from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import App from '@/App';
3+
import App from '@src/App';
44

55
// This line is to emulate what frontend-platform does when i18n initializes.
66
// It's necessary because our stylesheet is generated with `[dir="ltr"]` as a prefix on all

example/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"rootDir": ".",
55
"outDir": "dist",
66
"paths": {
7-
"@/*": ["./src/*"]
7+
"@src/*": ["./src/*"]
88
},
99
},
1010
"include": [

0 commit comments

Comments
 (0)