Skip to content
Draft
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
13 changes: 12 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@
"react/require-default-props": "off",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"import/prefer-default-export":"off"
}
},
"overrides": [
{
"parserOptions": {
"project": "./configs/tsconfig.json"
},
"files": ["./configs/**/*.ts"],
"rules": {
"import/no-extraneous-dependencies": ["error", {"optionalDependencies": true, "peerDependencies": true}]
}
}
]
}
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/coverage
/dist
/node_modules
/vite.config.ts-timestamp-*
/vite.config.mts-timestamp-*
.vite-inspect/
/coverage/
/dist/
/node_modules/
npm-debug.log*
/.idea
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
/.idea/
/.vscode/
*.tgz
*.log
57 changes: 57 additions & 0 deletions configs/react-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright © 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { type CommonServerOptions, type ConfigEnv, mergeConfig, type UserConfig } from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
// @ts-expect-error TS7016: Could not find a declaration file
import eslint from 'vite-plugin-eslint';
import tsconfigPaths from 'vite-tsconfig-paths';

export default function defineReactAppConfig(
/** Vite configuration environment */
config: ConfigEnv,
/** The IP port on which the dev server will bind on (range: [1;65535]) */
devPort: number,
/** Extra configuration to merge on top of this base config */
overrides: UserConfig = {}
): UserConfig {
const serverSettings: CommonServerOptions = {
port: devPort,
proxy: {
'/api/gateway': {
target: 'http://localhost:9000',
rewrite: (path: string) => path.replace(/^\/api\/gateway/i, ''),
},
'/ws/gateway': {
target: 'http://localhost:9000',
rewrite: (path: string) => path.replace(/^\/ws\/gateway/i, ''),
ws: true,
},
},
};
return mergeConfig(
{
plugins: [
react(),
svgr(), // works on every import with the pattern "**/*.svg?react"
eslint({
failOnWarning: config.mode !== 'development',
lintOnStart: true,
}),
tsconfigPaths(), // to resolve absolute path via tsconfig cf https://stackoverflow.com/a/68250175/5092999
],
base: './',
server: serverSettings, // for npm run start
preview: serverSettings, // for npm run serve (use local build)
build: {
outDir: 'build',
},
},
overrides
);
}
51 changes: 51 additions & 0 deletions configs/react-library/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright © 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { type ConfigEnv, mergeConfig, type UserConfig } from 'vite';
// @ts-expect-error TS7016: Could not find a declaration file
import eslint from 'vite-plugin-eslint';
import dts from 'vite-plugin-dts';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import * as path from 'node:path';

export default function defineReactLibConfig(
/** Vite configuration environment */
config: ConfigEnv,
/** Extra configuration to merge on top of this base config */
overrides: UserConfig = {}
): UserConfig {
return mergeConfig(
{
plugins: [
react(),
svgr(), // works on every import with the pattern "**/*.svg?react"
eslint({
failOnWarning: config.mode !== 'development',
lintOnStart: true,
}),
dts({
include: ['src'],
exclude: ['**/*.{spec,test}.{ts,tsx}'],
}),
],
build: {
outDir: 'dist',
minify: false, // easier to debug on the apps using this lib
lib: {
formats: ['es'],
},
rollupOptions: {
external: (importId: string) =>
importId.includes('/node_modules/') ||
(!importId.startsWith('.') && !path.isAbsolute(importId)),
},
},
},
overrides
);
}
17 changes: 17 additions & 0 deletions configs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "Node16",
"moduleResolution": "node16",
"target": "ESNext",
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"rootDir": ".",
"outDir": "../dist/configs",
"traceResolution": true
},
"include": ["./**/*.ts"]
}
Loading
Loading