Add TypeScript config for @mailpoet/components

This handles both type checking and type declaration emitting.

[MAILPOET-5015]
This commit is contained in:
Jan Jakes
2023-01-26 14:56:37 +01:00
committed by Jan Jakeš
parent 2aaf01fe11
commit 8fbe37dc4d
5 changed files with 54 additions and 19 deletions

View File

@ -1,2 +1,3 @@
/build
/build-module
/build-types

View File

@ -10,6 +10,7 @@
"import": "./build-module/index.js"
}
},
"types": "build-types/index.d.ts",
"scripts": {
"build": "wp-scripts build",
"start": "wp-scripts start"
@ -21,6 +22,7 @@
"devDependencies": {
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"fork-ts-checker-webpack-plugin": "^7.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},

View File

@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"include": ["src/**/*"],
"compilerOptions": {
"rootDir": "src",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "build-types"
}
}

View File

@ -1,5 +1,6 @@
import path from 'node:path';
import { default as defaultConfig } from '@wordpress/scripts/config/webpack.config.js';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { WebpackEmitAllPlugin } from '../../../tools/webpack/webpack-emit-all-plugin.js';
const dirname = new URL('.', import.meta.url).pathname;
@ -9,6 +10,7 @@ const plugins = [
(plugin) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin',
),
new WebpackEmitAllPlugin({ context: path.join(dirname, 'src') }),
new ForkTsCheckerWebpackPlugin({ typescript: { mode: 'write-dts' } }),
];
export default {