mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove webpack.*.ts importing values from src/ (#4992)
This commit is contained in:
parent
d5528eb9fe
commit
e977890677
@ -17,11 +17,11 @@
|
|||||||
"debug-build": "concurrently yarn:compile:main yarn:compile:extension-types",
|
"debug-build": "concurrently yarn:compile:main yarn:compile:extension-types",
|
||||||
"dev-run": "nodemon --watch ./static/build/main.js --exec \"electron --remote-debugging-port=9223 --inspect .\"",
|
"dev-run": "nodemon --watch ./static/build/main.js --exec \"electron --remote-debugging-port=9223 --inspect .\"",
|
||||||
"dev:main": "yarn run compile:main --watch --progress",
|
"dev:main": "yarn run compile:main --watch --progress",
|
||||||
"dev:renderer": "yarn run ts-node webpack.dev-server.ts",
|
"dev:renderer": "yarn run ts-node webpack/dev-server.ts",
|
||||||
"compile": "env NODE_ENV=production concurrently yarn:compile:*",
|
"compile": "env NODE_ENV=production concurrently yarn:compile:*",
|
||||||
"compile:main": "yarn run webpack --config webpack.main.ts",
|
"compile:main": "yarn run webpack --config webpack/main.ts",
|
||||||
"compile:renderer": "yarn run webpack --config webpack.renderer.ts",
|
"compile:renderer": "yarn run webpack --config webpack/renderer.ts",
|
||||||
"compile:extension-types": "yarn run webpack --config webpack.extensions.ts",
|
"compile:extension-types": "yarn run webpack --config webpack/extensions.ts",
|
||||||
"npm:fix-build-version": "yarn run ts-node build/set_build_version.ts",
|
"npm:fix-build-version": "yarn run ts-node build/set_build_version.ts",
|
||||||
"npm:fix-package-version": "yarn run ts-node build/set_npm_version.ts",
|
"npm:fix-package-version": "yarn run ts-node build/set_npm_version.ts",
|
||||||
"build:linux": "yarn run compile && electron-builder --linux --dir",
|
"build:linux": "yarn run compile && electron-builder --linux --dir",
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Setup variable in global scope (top-level object)
|
|
||||||
// Global type definition must be added separately to `mocks.d.ts` in form:
|
|
||||||
// declare const __globalName: any;
|
|
||||||
|
|
||||||
export function defineGlobal(propName: string, descriptor: PropertyDescriptor) {
|
|
||||||
const scope = typeof global !== "undefined" ? global : window;
|
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(scope, propName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.defineProperty(scope, propName, descriptor);
|
|
||||||
}
|
|
||||||
@ -20,7 +20,6 @@ export * from "./collection-functions";
|
|||||||
export * from "./convertCpu";
|
export * from "./convertCpu";
|
||||||
export * from "./convertMemory";
|
export * from "./convertMemory";
|
||||||
export * from "./debouncePromise";
|
export * from "./debouncePromise";
|
||||||
export * from "./defineGlobal";
|
|
||||||
export * from "./delay";
|
export * from "./delay";
|
||||||
export * from "./disposer";
|
export * from "./disposer";
|
||||||
export * from "./downloadFile";
|
export * from "./downloadFile";
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
import packageInfo from "../../package.json";
|
import packageInfo from "../../package.json";
|
||||||
import { defineGlobal } from "./utils/defineGlobal";
|
|
||||||
import { lazyInitialized } from "./utils/lazy-initialized";
|
import { lazyInitialized } from "./utils/lazy-initialized";
|
||||||
|
|
||||||
export const isMac = process.platform === "darwin";
|
export const isMac = process.platform === "darwin";
|
||||||
@ -101,26 +100,12 @@ export const kubectlBinaryName = getBinaryName("kubectl");
|
|||||||
* @deprecated for being explicit side effect.
|
* @deprecated for being explicit side effect.
|
||||||
*/
|
*/
|
||||||
export const kubectlBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), kubectlBinaryName));
|
export const kubectlBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), kubectlBinaryName));
|
||||||
|
export const staticFilesDirectory = path.resolve(
|
||||||
// Webpack build paths
|
!isProduction
|
||||||
export const contextDir = process.cwd();
|
? process.cwd()
|
||||||
export const buildDir = path.join(contextDir, "static", publicPath);
|
: process.resourcesPath,
|
||||||
export const preloadEntrypoint = path.join(contextDir, "src/preload.ts");
|
"static",
|
||||||
export const mainDir = path.join(contextDir, "src/main");
|
);
|
||||||
export const rendererDir = path.join(contextDir, "src/renderer");
|
|
||||||
export const htmlTemplate = path.resolve(rendererDir, "template.html");
|
|
||||||
export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss");
|
|
||||||
|
|
||||||
// Special runtime paths
|
|
||||||
defineGlobal("__static", {
|
|
||||||
get() {
|
|
||||||
const root = isDevelopment
|
|
||||||
? contextDir
|
|
||||||
: (process.resourcesPath ?? contextDir);
|
|
||||||
|
|
||||||
return path.resolve(root, "static");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apis
|
// Apis
|
||||||
export const apiPrefix = "/api" as string; // local router apis
|
export const apiPrefix = "/api" as string; // local router apis
|
||||||
@ -142,5 +127,3 @@ export const appSemVer = new SemVer(packageInfo.version);
|
|||||||
export const docsUrl = "https://docs.k8slens.dev/main/" as string;
|
export const docsUrl = "https://docs.k8slens.dev/main/" as string;
|
||||||
|
|
||||||
export const sentryDsn = packageInfo.config?.sentryDsn ?? "";
|
export const sentryDsn = packageInfo.config?.sentryDsn ?? "";
|
||||||
|
|
||||||
export const webpackDevServerPort: number = Number(process.env.WEBPACK_DEV_SERVER_PORT) || 9191;
|
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import { contextDir } from "../vars";
|
|
||||||
|
|
||||||
const contextDirInjectable = getInjectable({
|
|
||||||
id: "context-dir",
|
|
||||||
instantiate: () => contextDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default contextDirInjectable;
|
|
||||||
@ -16,7 +16,7 @@ import logger from "../../main/logger";
|
|||||||
import type { ExtensionsStore } from "../extensions-store/extensions-store";
|
import type { ExtensionsStore } from "../extensions-store/extensions-store";
|
||||||
import type { ExtensionLoader } from "../extension-loader";
|
import type { ExtensionLoader } from "../extension-loader";
|
||||||
import type { LensExtensionId, LensExtensionManifest } from "../lens-extension";
|
import type { LensExtensionId, LensExtensionManifest } from "../lens-extension";
|
||||||
import { isProduction } from "../../common/vars";
|
import { isProduction, staticFilesDirectory } from "../../common/vars";
|
||||||
import type { ExtensionInstallationStateStore } from "../extension-installation-state-store/extension-installation-state-store";
|
import type { ExtensionInstallationStateStore } from "../extension-installation-state-store/extension-installation-state-store";
|
||||||
import type { PackageJson } from "type-fest";
|
import type { PackageJson } from "type-fest";
|
||||||
import { extensionDiscoveryStateChannel } from "../../common/ipc/extension-handling";
|
import { extensionDiscoveryStateChannel } from "../../common/ipc/extension-handling";
|
||||||
@ -112,7 +112,7 @@ export class ExtensionDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get inTreeFolderPath(): string {
|
get inTreeFolderPath(): string {
|
||||||
return path.resolve(__static, "../extensions");
|
return path.resolve(staticFilesDirectory, "../extensions");
|
||||||
}
|
}
|
||||||
|
|
||||||
get nodeModulesPath(): string {
|
get nodeModulesPath(): string {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import httpProxy from "http-proxy";
|
|||||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||||
import * as LensExtensionsMainApi from "../extensions/main-api";
|
import * as LensExtensionsMainApi from "../extensions/main-api";
|
||||||
import { app, autoUpdater, dialog, powerMonitor } from "electron";
|
import { app, autoUpdater, dialog, powerMonitor } from "electron";
|
||||||
import { appName, isIntegrationTesting, isMac, isWindows, productName } from "../common/vars";
|
import { appName, isIntegrationTesting, isMac, isWindows, productName, staticFilesDirectory } from "../common/vars";
|
||||||
import { LensProxy } from "./lens-proxy";
|
import { LensProxy } from "./lens-proxy";
|
||||||
import { WindowManager } from "./window-manager";
|
import { WindowManager } from "./window-manager";
|
||||||
import { ClusterManager } from "./cluster-manager";
|
import { ClusterManager } from "./cluster-manager";
|
||||||
@ -198,7 +198,7 @@ async function main(di: DiContainer) {
|
|||||||
|
|
||||||
powerMonitor.on("shutdown", () => app.exit());
|
powerMonitor.on("shutdown", () => app.exit());
|
||||||
|
|
||||||
registerFileProtocol("static", __static);
|
registerFileProtocol("static", staticFilesDirectory);
|
||||||
|
|
||||||
PrometheusProviderRegistry.createInstance();
|
PrometheusProviderRegistry.createInstance();
|
||||||
initializers.initPrometheusProviderRegistry();
|
initializers.initPrometheusProviderRegistry();
|
||||||
|
|||||||
@ -11,9 +11,6 @@ import type { Cluster } from "../../common/cluster/cluster";
|
|||||||
import type { LensApiResultContentType } from "./router-content-types";
|
import type { LensApiResultContentType } from "./router-content-types";
|
||||||
import { contentTypes } from "./router-content-types";
|
import { contentTypes } from "./router-content-types";
|
||||||
|
|
||||||
// TODO: Import causes side effect, sets value for __static
|
|
||||||
import "../../common/vars";
|
|
||||||
|
|
||||||
export interface RouterRequestOpts {
|
export interface RouterRequestOpts {
|
||||||
req: http.IncomingMessage;
|
req: http.IncomingMessage;
|
||||||
res: http.ServerResponse;
|
res: http.ServerResponse;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import type { SupportedFileExtension } from "../router/router-content-types";
|
|||||||
import { contentTypes } from "../router/router-content-types";
|
import { contentTypes } from "../router/router-content-types";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { routeInjectionToken } from "../router/router.injectable";
|
import { routeInjectionToken } from "../router/router.injectable";
|
||||||
import { appName, publicPath, webpackDevServerPort } from "../../common/vars";
|
import { appName, publicPath, staticFilesDirectory } from "../../common/vars";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||||
import httpProxy from "http-proxy";
|
import httpProxy from "http-proxy";
|
||||||
@ -17,6 +17,7 @@ import type { GetAbsolutePath } from "../../common/path/get-absolute-path.inject
|
|||||||
import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable";
|
import getAbsolutePathInjectable from "../../common/path/get-absolute-path.injectable";
|
||||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||||
|
import { webpackDevServerPort } from "../../../webpack/vars";
|
||||||
|
|
||||||
interface ProductionDependencies {
|
interface ProductionDependencies {
|
||||||
readFileBuffer: (path: string) => Promise<Buffer>;
|
readFileBuffer: (path: string) => Promise<Buffer>;
|
||||||
@ -27,7 +28,7 @@ interface ProductionDependencies {
|
|||||||
const handleStaticFileInProduction =
|
const handleStaticFileInProduction =
|
||||||
({ readFileBuffer, getAbsolutePath, joinPaths }: ProductionDependencies) =>
|
({ readFileBuffer, getAbsolutePath, joinPaths }: ProductionDependencies) =>
|
||||||
async ({ params }: LensApiRequest) => {
|
async ({ params }: LensApiRequest) => {
|
||||||
const staticPath = getAbsolutePath(__static);
|
const staticPath = getAbsolutePath(staticFilesDirectory);
|
||||||
let filePath = params.path;
|
let filePath = params.path;
|
||||||
|
|
||||||
for (let retryCount = 0; retryCount < 5; retryCount += 1) {
|
for (let retryCount = 0; retryCount < 5; retryCount += 1) {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { showAbout } from "../menu/menu";
|
|||||||
import { checkForUpdates, isAutoUpdateEnabled } from "../app-updater";
|
import { checkForUpdates, isAutoUpdateEnabled } from "../app-updater";
|
||||||
import type { WindowManager } from "../window-manager";
|
import type { WindowManager } from "../window-manager";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { isDevelopment, isWindows, productName } from "../../common/vars";
|
import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars";
|
||||||
import { exitApp } from "../exit-app";
|
import { exitApp } from "../exit-app";
|
||||||
import { toJS } from "../../common/utils";
|
import { toJS } from "../../common/utils";
|
||||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||||
@ -25,7 +25,7 @@ export let tray: Tray;
|
|||||||
|
|
||||||
export function getTrayIcon(): string {
|
export function getTrayIcon(): string {
|
||||||
return path.resolve(
|
return path.resolve(
|
||||||
__static,
|
staticFilesDirectory,
|
||||||
isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras
|
isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras
|
||||||
"trayIconTemplate.png",
|
"trayIconTemplate.png",
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { hasCorrectExtension } from "./has-correct-extension";
|
import { hasCorrectExtension } from "./has-correct-extension";
|
||||||
import "../../../../common/vars";
|
import { staticFilesDirectory } from "../../../../common/vars";
|
||||||
import readFileInjectable from "../../../../common/fs/read-file.injectable";
|
import readFileInjectable from "../../../../common/fs/read-file.injectable";
|
||||||
import readDirInjectable from "../../../../common/fs/read-dir.injectable";
|
import readDirInjectable from "../../../../common/fs/read-dir.injectable";
|
||||||
import type { RawTemplates } from "./create-resource-templates.injectable";
|
import type { RawTemplates } from "./create-resource-templates.injectable";
|
||||||
@ -19,7 +19,7 @@ interface Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getTemplates({ readDir, readFile, getAbsolutePath }: Dependencies) {
|
async function getTemplates({ readDir, readFile, getAbsolutePath }: Dependencies) {
|
||||||
const templatesFolder = getAbsolutePath(__static, "../templates/create-resource");
|
const templatesFolder = getAbsolutePath(staticFilesDirectory, "../templates/create-resource");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping between file names and their contents
|
* Mapping between file names and their contents
|
||||||
|
|||||||
@ -32,7 +32,11 @@
|
|||||||
"types/*"
|
"types/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"plugins": [{ "name": "typescript-plugin-css-modules" }]
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "typescript-plugin-css-modules"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"ts-node": {
|
"ts-node": {
|
||||||
"transpileOnly": true,
|
"transpileOnly": true,
|
||||||
@ -42,7 +46,7 @@
|
|||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
"types/*.d.ts"
|
"types/*.d.ts",
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|||||||
3
types/mocks.d.ts
vendored
3
types/mocks.d.ts
vendored
@ -8,9 +8,6 @@ declare module "win-ca/api"
|
|||||||
declare module "@hapi/call"
|
declare module "@hapi/call"
|
||||||
declare module "@hapi/subtext"
|
declare module "@hapi/subtext"
|
||||||
|
|
||||||
// Global path to static assets
|
|
||||||
declare const __static: string;
|
|
||||||
|
|
||||||
// Support import for custom module extensions
|
// Support import for custom module extensions
|
||||||
// https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
|
// https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
|
||||||
declare module "*.module.scss" {
|
declare module "*.module.scss" {
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Webpack from "webpack";
|
|
||||||
import WebpackDevServer from "webpack-dev-server";
|
|
||||||
import { webpackLensRenderer } from "./webpack.renderer";
|
|
||||||
import { buildDir, webpackDevServerPort } from "./src/common/vars";
|
|
||||||
import logger from "./src/common/logger";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates `webpack-dev-server`
|
|
||||||
* API docs:
|
|
||||||
* @url https://webpack.js.org/configuration/dev-server/
|
|
||||||
* @url https://github.com/chimurai/http-proxy-middleware
|
|
||||||
*/
|
|
||||||
function createDevServer(): WebpackDevServer {
|
|
||||||
const config = webpackLensRenderer({ showVars: false });
|
|
||||||
const compiler = Webpack(config);
|
|
||||||
|
|
||||||
const server = new WebpackDevServer({
|
|
||||||
setupExitSignals: true,
|
|
||||||
headers: {
|
|
||||||
"Access-Control-Allow-Origin": "*",
|
|
||||||
},
|
|
||||||
allowedHosts: "all",
|
|
||||||
host: "localhost",
|
|
||||||
port: webpackDevServerPort,
|
|
||||||
static: buildDir, // aka `devServer.contentBase` in webpack@4
|
|
||||||
hot: "only", // use HMR only without errors
|
|
||||||
liveReload: false,
|
|
||||||
devMiddleware: {
|
|
||||||
writeToDisk: false,
|
|
||||||
index: "OpenLensDev.html",
|
|
||||||
publicPath: "/build",
|
|
||||||
},
|
|
||||||
proxy: {
|
|
||||||
"^/$": "/build/",
|
|
||||||
},
|
|
||||||
client: {
|
|
||||||
overlay: false, // don't show warnings and errors on top of rendered app view
|
|
||||||
logging: "error",
|
|
||||||
},
|
|
||||||
}, compiler);
|
|
||||||
|
|
||||||
logger.info(`[WEBPACK-DEV-SERVER]: created with options`, server.options);
|
|
||||||
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = createDevServer();
|
|
||||||
|
|
||||||
server.start();
|
|
||||||
47
webpack/dev-server.ts
Normal file
47
webpack/dev-server.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Webpack from "webpack";
|
||||||
|
import WebpackDevServer from "webpack-dev-server";
|
||||||
|
import { webpackLensRenderer } from "./renderer";
|
||||||
|
import logger from "../src/common/logger";
|
||||||
|
import { buildDir, webpackDevServerPort } from "./vars";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API docs:
|
||||||
|
* @url https://webpack.js.org/configuration/dev-server/
|
||||||
|
* @url https://github.com/chimurai/http-proxy-middleware
|
||||||
|
*/
|
||||||
|
const config = webpackLensRenderer({ showVars: false });
|
||||||
|
const compiler = Webpack(config);
|
||||||
|
|
||||||
|
const server = new WebpackDevServer({
|
||||||
|
setupExitSignals: true,
|
||||||
|
headers: {
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
},
|
||||||
|
allowedHosts: "all",
|
||||||
|
host: "localhost",
|
||||||
|
port: webpackDevServerPort,
|
||||||
|
static: buildDir, // aka `devServer.contentBase` in webpack@4
|
||||||
|
hot: "only", // use HMR only without errors
|
||||||
|
liveReload: false,
|
||||||
|
devMiddleware: {
|
||||||
|
writeToDisk: false,
|
||||||
|
index: "OpenLensDev.html",
|
||||||
|
publicPath: "/build",
|
||||||
|
},
|
||||||
|
proxy: {
|
||||||
|
"^/$": "/build/",
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
overlay: false, // don't show warnings and errors on top of rendered app view
|
||||||
|
logging: "error",
|
||||||
|
},
|
||||||
|
}, compiler);
|
||||||
|
|
||||||
|
logger.info(`[WEBPACK-DEV-SERVER]: created with options`, server.options);
|
||||||
|
|
||||||
|
server.start();
|
||||||
@ -6,25 +6,21 @@
|
|||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import type webpack from "webpack";
|
import type webpack from "webpack";
|
||||||
import * as vars from "./src/common/vars";
|
import { cssModulesWebpackRule, fontsLoaderWebpackRules, iconsAndImagesWebpackRules } from "./renderer";
|
||||||
import { cssModulesWebpackRule, fontsLoaderWebpackRules, iconsAndImagesWebpackRules } from "./webpack.renderer";
|
import { extensionEntry, extensionOutDir, isDevelopment } from "./vars";
|
||||||
|
|
||||||
export default function generateExtensionTypes(): webpack.Configuration {
|
export default function generateExtensionTypes(): webpack.Configuration {
|
||||||
const { isDevelopment } = vars;
|
|
||||||
const entry = "./src/extensions/extension-api.ts";
|
|
||||||
const outDir = "./src/extensions/npm/extensions/dist";
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Compile for Electron for renderer process
|
// Compile for Electron for renderer process
|
||||||
// see <https://webpack.js.org/configuration/target/>
|
// see <https://webpack.js.org/configuration/target/>
|
||||||
target: "electron-renderer",
|
target: "electron-renderer",
|
||||||
entry,
|
entry: extensionEntry,
|
||||||
// this is the default mode, so we should make it explicit to silence the warning
|
// this is the default mode, so we should make it explicit to silence the warning
|
||||||
mode: isDevelopment ? "development" : "production",
|
mode: isDevelopment ? "development" : "production",
|
||||||
output: {
|
output: {
|
||||||
filename: "extension-api.js",
|
filename: "extension-api.js",
|
||||||
// need to be an absolute path
|
// need to be an absolute path
|
||||||
path: path.resolve(__dirname, `${outDir}/src/extensions`),
|
path: path.resolve(extensionOutDir, "src", "extensions"),
|
||||||
// can be use in commonjs environments
|
// can be use in commonjs environments
|
||||||
// e.g. require('@k8slens/extensions')
|
// e.g. require('@k8slens/extensions')
|
||||||
libraryTarget: "commonjs",
|
libraryTarget: "commonjs",
|
||||||
@ -54,7 +50,7 @@ export default function generateExtensionTypes(): webpack.Configuration {
|
|||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
declaration: true, // output .d.ts
|
declaration: true, // output .d.ts
|
||||||
sourceMap: false, // to override sourceMap: true in tsconfig.json
|
sourceMap: false, // to override sourceMap: true in tsconfig.json
|
||||||
outDir, // where the .d.ts should be located
|
outDir: extensionOutDir, // where the .d.ts should be located
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -11,7 +11,7 @@ import type { Options as TSLoaderOptions } from "ts-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
|
||||||
*/
|
*/
|
||||||
const getTSLoader = (options: Partial<TSLoaderOptions> = {}, testRegExp?: RegExp) => {
|
export default function getTypescriptLoader(options: Partial<TSLoaderOptions> = {}, testRegExp?: RegExp) {
|
||||||
testRegExp ??= /\.tsx?$/; // by default covers react/jsx-stuff
|
testRegExp ??= /\.tsx?$/; // by default covers react/jsx-stuff
|
||||||
options.transpileOnly ??= true;
|
options.transpileOnly ??= true;
|
||||||
|
|
||||||
@ -37,6 +37,4 @@ const getTSLoader = (options: Partial<TSLoaderOptions> = {}, testRegExp?: RegExp
|
|||||||
options,
|
options,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getTSLoader;
|
|
||||||
@ -7,16 +7,20 @@ 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 * as vars from "./src/common/vars";
|
import getTypeScriptLoader from "./get-typescript-loader";
|
||||||
import getTSLoader from "./src/common/getTSLoader";
|
|
||||||
import CircularDependencyPlugin from "circular-dependency-plugin";
|
import CircularDependencyPlugin from "circular-dependency-plugin";
|
||||||
import { iconsAndImagesWebpackRules } from "./webpack.renderer";
|
import { iconsAndImagesWebpackRules } from "./renderer";
|
||||||
|
import type { WebpackPluginInstance } from "webpack";
|
||||||
|
import { buildDir, isDevelopment, mainDir } from "./vars";
|
||||||
|
|
||||||
const configs: { (): webpack.Configuration }[] = [];
|
const configs: { (): webpack.Configuration }[] = [];
|
||||||
|
|
||||||
configs.push((): webpack.Configuration => {
|
configs.push((): webpack.Configuration => {
|
||||||
console.info("WEBPACK:main", { ...vars });
|
console.info("WEBPACK:main", {
|
||||||
const { mainDir, buildDir, isDevelopment } = vars;
|
isDevelopment,
|
||||||
|
mainDir,
|
||||||
|
buildDir,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "lens-app-main",
|
name: "lens-app-main",
|
||||||
@ -44,7 +48,7 @@ configs.push((): webpack.Configuration => {
|
|||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
use: "node-loader",
|
use: "node-loader",
|
||||||
},
|
},
|
||||||
getTSLoader({}, /\.ts$/),
|
getTypeScriptLoader({}, /\.ts$/),
|
||||||
...iconsAndImagesWebpackRules(),
|
...iconsAndImagesWebpackRules(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -54,8 +58,8 @@ configs.push((): webpack.Configuration => {
|
|||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
failOnError: true,
|
failOnError: true,
|
||||||
}),
|
}) as unknown as WebpackPluginInstance,
|
||||||
].filter(Boolean),
|
],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -3,25 +3,31 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as vars from "./src/common/vars";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import type webpack from "webpack";
|
import type webpack from "webpack";
|
||||||
import HtmlWebpackPlugin from "html-webpack-plugin";
|
import HtmlWebpackPlugin from "html-webpack-plugin";
|
||||||
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
||||||
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
||||||
import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
|
import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
|
||||||
import getTSLoader from "./src/common/getTSLoader";
|
|
||||||
import CircularDependencyPlugin from "circular-dependency-plugin";
|
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 getTypescriptLoader from "./get-typescript-loader";
|
||||||
|
import { assetsFolderName, isDevelopment, rendererDir, buildDir, appName, htmlTemplate, publicPath, sassCommonVars } from "./vars";
|
||||||
|
|
||||||
export function webpackLensRenderer({ showVars = true } = {}): webpack.Configuration {
|
export function webpackLensRenderer({ showVars = true } = {}): webpack.Configuration {
|
||||||
if (showVars) {
|
if (showVars) {
|
||||||
console.info("WEBPACK:renderer", { ...vars });
|
console.info("WEBPACK:renderer", {
|
||||||
|
assetsFolderName,
|
||||||
|
isDevelopment,
|
||||||
|
rendererDir,
|
||||||
|
buildDir,
|
||||||
|
appName,
|
||||||
|
htmlTemplate,
|
||||||
|
publicPath,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetsFolderName = "assets";
|
|
||||||
const { appName, buildDir, htmlTemplate, isDevelopment, publicPath, rendererDir } = vars;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
target: "electron-renderer",
|
target: "electron-renderer",
|
||||||
name: "lens-app-renderer",
|
name: "lens-app-renderer",
|
||||||
@ -67,7 +73,7 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
|||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
use: "node-loader",
|
use: "node-loader",
|
||||||
},
|
},
|
||||||
getTSLoader({
|
getTypescriptLoader({
|
||||||
getCustomTransformers: () => ({
|
getCustomTransformers: () => ({
|
||||||
before: isDevelopment ? [require("react-refresh-typescript")()] : [],
|
before: isDevelopment ? [require("react-refresh-typescript")()] : [],
|
||||||
}),
|
}),
|
||||||
@ -103,14 +109,18 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
|||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
failOnError: true,
|
failOnError: true,
|
||||||
}),
|
}) as unknown as WebpackPluginInstance,
|
||||||
|
|
||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: "[name].css",
|
filename: "[name].css",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
isDevelopment && new ReactRefreshWebpackPlugin(),
|
...(
|
||||||
].filter(Boolean),
|
isDevelopment
|
||||||
|
? [new ReactRefreshWebpackPlugin()]
|
||||||
|
: []
|
||||||
|
),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,15 +153,17 @@ export function fontsLoaderWebpackRules(): webpack.RuleSetRule[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CssModulesWebpackRuleOptions {
|
||||||
|
styleLoader?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import CSS or SASS styles with modules support (*.module.scss)
|
* Import CSS or SASS styles with modules support (*.module.scss)
|
||||||
* @param {string} styleLoader
|
|
||||||
*/
|
*/
|
||||||
export function cssModulesWebpackRule(
|
export function cssModulesWebpackRule({ styleLoader }: CssModulesWebpackRuleOptions = {}): webpack.RuleSetRule {
|
||||||
{
|
styleLoader ??= isDevelopment
|
||||||
styleLoader = vars.isDevelopment ? "style-loader" : MiniCssExtractPlugin.loader,
|
? "style-loader"
|
||||||
} = {}): webpack.RuleSetRule {
|
: MiniCssExtractPlugin.loader;
|
||||||
const { isDevelopment, sassCommonVars } = vars;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
test: /\.s?css$/,
|
test: /\.s?css$/,
|
||||||
3
webpack/tsconfig.json
Normal file
3
webpack/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json"
|
||||||
|
}
|
||||||
25
webpack/vars.ts
Normal file
25
webpack/vars.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import assert from "assert";
|
||||||
|
import path from "path";
|
||||||
|
import packageInfo from "../package.json";
|
||||||
|
|
||||||
|
export const isDevelopment = process.env.NODE_ENV !== "production";
|
||||||
|
export const mainDir = path.join(process.cwd(), "src", "main");
|
||||||
|
export const buildDir = path.join(process.cwd(), "static", "build");
|
||||||
|
export const extensionEntry = path.join(process.cwd(), "src", "extensions", "extension-api.ts");
|
||||||
|
export const extensionOutDir = path.join(process.cwd(), "src", "extensions", "npm", "extensions", "dist");
|
||||||
|
export const assetsFolderName = "assets";
|
||||||
|
export const rendererDir = path.join(process.cwd(), "src", "renderer");
|
||||||
|
export const appName = isDevelopment
|
||||||
|
? `${packageInfo.productName}Dev`
|
||||||
|
: packageInfo.productName;
|
||||||
|
export const htmlTemplate = path.resolve(rendererDir, "template.html");
|
||||||
|
export const publicPath = "/build/";
|
||||||
|
export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss");
|
||||||
|
export const webpackDevServerPort = Number(process.env.WEBPACK_DEV_SERVER_PORT) || 9191;
|
||||||
|
|
||||||
|
assert(Number.isInteger(webpackDevServerPort), "WEBPACK_DEV_SERVER_PORT environment variable must only be an integer");
|
||||||
Loading…
Reference in New Issue
Block a user