Skip to content

Commit cd49b15

Browse files
feat: ensure Webpack and ESLint adhere to tsconfig.json paths (#636)
1 parent 0d58131 commit cd49b15

8 files changed

+392
-8
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = createConfig('eslint', {
77
'global-require': 'off',
88
'no-template-curly-in-string': 'off',
99
},
10+
ignorePatterns: ['example/**/*'],
1011
});

config/.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ module.exports = {
3737
'import/no-import-module-export': 'off',
3838
'react/function-component-definition': [2, { namedComponents: 'arrow-function' }],
3939
},
40+
settings: {
41+
'import/resolver': {
42+
typescript: {},
43+
},
44+
},
4045
globals: {
4146
newrelic: false,
4247
PARAGON_THEME: false,

config/webpack.common.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
3+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
34

45
const ParagonWebpackPlugin = require('../lib/plugins/paragon-webpack-plugin/ParagonWebpackPlugin');
56
const {
@@ -45,6 +46,9 @@ module.exports = {
4546
'env.config': false,
4647
},
4748
extensions: ['.js', '.jsx', '.ts', '.tsx'],
49+
plugins: [
50+
new TsconfigPathsPlugin(),
51+
],
4852
},
4953
optimization: {
5054
splitChunks: {
@@ -59,7 +63,6 @@ module.exports = {
5963
// RemoveEmptyScriptsPlugin get rid of empty scripts generated by webpack when using mini-css-extract-plugin
6064
// This helps to clean up the final bundle application
6165
// See: https://www.npmjs.com/package/webpack-remove-empty-scripts#usage-with-mini-css-extract-plugin
62-
6366
new RemoveEmptyScriptsPlugin(),
6467
new ParagonWebpackPlugin(),
6568
],

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "../bin/fedx-scripts.js jest ./src",
88
"build": "../bin/fedx-scripts.js webpack",
9-
"lint": "../bin/fedx-scripts.js eslint . --ext .jsx,.js",
9+
"lint": "../bin/fedx-scripts.js eslint --ext .jsx --ext .js --ext .ts --ext .tsx",
1010
"babel": "../bin/fedx-scripts.js babel src --out-dir dist/babel --source-maps --ignore **/*.test.jsx,**/*.test.js --copy-files",
1111
"start": "../bin/fedx-scripts.js webpack-dev-server",
1212
"serve": "../bin/fedx-scripts.js serve"
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 '@/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
@@ -9,5 +9,7 @@ import App from './App';
99
global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');
1010

1111
const rootContainer = document.getElementById('root');
12-
const root = createRoot(rootContainer);
13-
root.render(<StrictMode><App /></StrictMode>);
12+
if (rootContainer) {
13+
const root = createRoot(rootContainer);
14+
root.render(<StrictMode><App /></StrictMode>);
15+
}

example/tsconfig.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"rootDir": ".",
5-
"outDir": "dist"
5+
"outDir": "dist",
6+
"paths": {
7+
"@/*": ["./src/*"]
8+
},
69
},
710
"include": [
811
".eslintrc.js",
@@ -13,4 +16,4 @@
1316
"node_modules",
1417
"dist",
1518
]
16-
}
19+
}

0 commit comments

Comments
 (0)