- attempt to use "react-refresh-typescript" with webpack@5 thingy

- extending getTSLoader() to accept more options from ts-loader

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2022-01-24 12:48:46 +02:00
1 parent 3782204bc4
commit 2f382d4986
6 files changed
+152 -95

No files matched your search

+7 -10
View File
@@ -4,18 +4,17 @@
*/
import esbuild from "esbuild";
import type { Options as TSLoaderOptions } from "ts-loader";
/**
* A function returning webpack ts/tsx loader
*
* depends on env LENS_DEV_USE_ESBUILD_LOADER to use esbuild-loader (faster) or good-old ts-loader
*
* @param testRegExp - the regex for webpack to conditional find the files
* @returns ts/tsx webpack loader configuration object
*/
const getTSLoader = (
testRegExp: RegExp, transpileOnly = true,
) => {
const getTSLoader = (options: Partial<TSLoaderOptions> = {}, testRegExp?: RegExp) => {
testRegExp ??= /\.tsx?$/; // by default covers react/jsx-stuff
options.transpileOnly ??= true; // requirement for "react-refresh-typescript"
if (process.env.LENS_DEV_USE_ESBUILD_LOADER === "true") {
console.info(`\n🚀 using esbuild-loader for ts(x)`);
@@ -34,10 +33,8 @@ const getTSLoader = (
test: testRegExp,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly,
},
loader: require.resolve("ts-loader"),
options,
},
};
};