mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup webpack configs (#7017)
- Deduplicate printing to console Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
06a930db57
commit
1182682c01
@ -5,36 +5,47 @@
|
|||||||
|
|
||||||
import esbuild from "esbuild";
|
import esbuild from "esbuild";
|
||||||
import type { Options as TSLoaderOptions } from "ts-loader";
|
import type { Options as TSLoaderOptions } from "ts-loader";
|
||||||
|
import { once } from "lodash";
|
||||||
|
|
||||||
|
const getTsLoader = (options: Partial<TSLoaderOptions>, testRegExp: RegExp) => ({
|
||||||
|
test: testRegExp,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: {
|
||||||
|
loader: "ts-loader",
|
||||||
|
options,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const printUsingEsbuildLoader = once(() => {
|
||||||
|
console.info(`\n🚀 using esbuild-loader for ts(x)`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const getEsbuildLoader = (options: Partial<TSLoaderOptions>, testRegExp: RegExp) => (printUsingEsbuildLoader(), {
|
||||||
|
test: testRegExp,
|
||||||
|
loader: "esbuild-loader",
|
||||||
|
options: {
|
||||||
|
loader: "tsx",
|
||||||
|
target: "ES2019",
|
||||||
|
implementation: esbuild,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const getTypescriptLoaderImpl = process.env.LENS_DEV_USE_ESBUILD_LOADER === "true"
|
||||||
|
? getEsbuildLoader
|
||||||
|
: getTsLoader;
|
||||||
|
|
||||||
|
// by default covers react/jsx-stuff
|
||||||
|
const defaultTestRegExp = /\.tsx?$/;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function returning webpack ts/tsx 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
|
* depends on env LENS_DEV_USE_ESBUILD_LOADER to use esbuild-loader (faster) or good-old ts-loader
|
||||||
* @returns ts/tsx webpack loader configuration object
|
* @returns ts/tsx webpack loader configuration object
|
||||||
*/
|
*/
|
||||||
export default function getTypescriptLoader(options: Partial<TSLoaderOptions> = {}, testRegExp?: RegExp) {
|
export const getTypescriptLoader = (options?: Partial<TSLoaderOptions>, testRegExp?: RegExp) => {
|
||||||
testRegExp ??= /\.tsx?$/; // by default covers react/jsx-stuff
|
options ??= {};
|
||||||
options.transpileOnly ??= true;
|
options.transpileOnly ??= true;
|
||||||
|
testRegExp ??= defaultTestRegExp;
|
||||||
|
|
||||||
if (process.env.LENS_DEV_USE_ESBUILD_LOADER === "true") {
|
return getTypescriptLoaderImpl(options, testRegExp);
|
||||||
console.info(`\n🚀 using esbuild-loader for ts(x)`);
|
};
|
||||||
|
|
||||||
return {
|
|
||||||
test: testRegExp,
|
|
||||||
loader: "esbuild-loader",
|
|
||||||
options: {
|
|
||||||
loader: "tsx",
|
|
||||||
target: "ES2019", // supported by >= electron@14
|
|
||||||
implementation: esbuild,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
test: testRegExp,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: {
|
|
||||||
loader: "ts-loader",
|
|
||||||
options,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@ -8,13 +8,14 @@ import path from "path";
|
|||||||
import { DefinePlugin, optimize } from "webpack";
|
import { DefinePlugin, optimize } from "webpack";
|
||||||
import main from "./main";
|
import main from "./main";
|
||||||
import renderer, { iconsAndImagesWebpackRules } from "./renderer";
|
import renderer, { iconsAndImagesWebpackRules } from "./renderer";
|
||||||
import { buildDir } from "./vars";
|
import { buildDir, isDevelopment } from "./vars";
|
||||||
|
|
||||||
const rendererConfig = renderer({ showVars: false });
|
const rendererConfig = renderer({ showVars: false });
|
||||||
|
const mainConfig = main();
|
||||||
|
|
||||||
const config = [
|
const config = [
|
||||||
{
|
{
|
||||||
...main(),
|
...mainConfig,
|
||||||
entry: {
|
entry: {
|
||||||
main: path.resolve(__dirname, "..", "src", "main", "library.ts"),
|
main: path.resolve(__dirname, "..", "src", "main", "library.ts"),
|
||||||
},
|
},
|
||||||
@ -62,7 +63,7 @@ const config = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...main(),
|
...mainConfig,
|
||||||
name: "lens-app-common",
|
name: "lens-app-common",
|
||||||
entry: {
|
entry: {
|
||||||
common: path.resolve(__dirname, "..", "src", "common", "library.ts"),
|
common: path.resolve(__dirname, "..", "src", "common", "library.ts"),
|
||||||
@ -106,7 +107,7 @@ const config = [
|
|||||||
}),
|
}),
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: "[name].css",
|
filename: "[name].css",
|
||||||
runtime: false,
|
runtime: isDevelopment,
|
||||||
}),
|
}),
|
||||||
new optimize.LimitChunkCountPlugin({
|
new optimize.LimitChunkCountPlugin({
|
||||||
maxChunks: 1,
|
maxChunks: 1,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import path from "path";
|
|||||||
import type webpack from "webpack";
|
import type webpack from "webpack";
|
||||||
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
||||||
import nodeExternals from "webpack-node-externals";
|
import nodeExternals from "webpack-node-externals";
|
||||||
import getTypeScriptLoader from "./get-typescript-loader";
|
import { getTypescriptLoader } from "./get-typescript-loader";
|
||||||
import CircularDependencyPlugin from "circular-dependency-plugin";
|
import CircularDependencyPlugin from "circular-dependency-plugin";
|
||||||
import { iconsAndImagesWebpackRules } from "./renderer";
|
import { iconsAndImagesWebpackRules } from "./renderer";
|
||||||
import type { WebpackPluginInstance } from "webpack";
|
import type { WebpackPluginInstance } from "webpack";
|
||||||
@ -56,7 +56,7 @@ const main = ({ showVars = true } = {}): webpack.Configuration => {
|
|||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
use: "node-loader",
|
use: "node-loader",
|
||||||
},
|
},
|
||||||
getTypeScriptLoader({}, /\.ts$/),
|
getTypescriptLoader({}, /\.ts$/),
|
||||||
...iconsAndImagesWebpackRules(),
|
...iconsAndImagesWebpackRules(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import CircularDependencyPlugin from "circular-dependency-plugin";
|
|||||||
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
||||||
import type { WebpackPluginInstance } from "webpack";
|
import type { WebpackPluginInstance } from "webpack";
|
||||||
import { DefinePlugin } from "webpack";
|
import { DefinePlugin } from "webpack";
|
||||||
import getTypescriptLoader from "./get-typescript-loader";
|
import { getTypescriptLoader } from "./get-typescript-loader";
|
||||||
import { assetsFolderName, isDevelopment, rendererDir, buildDir, appName, htmlTemplate, publicPath, sassCommonVars, additionalExternals } from "./vars";
|
import { assetsFolderName, isDevelopment, rendererDir, buildDir, appName, htmlTemplate, publicPath, sassCommonVars, additionalExternals } from "./vars";
|
||||||
import { platform } from "process";
|
import { platform } from "process";
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user