1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

webpack fixes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-12-19 15:23:43 +02:00
parent 2b0a30cf23
commit 2400c8577e
3 changed files with 15 additions and 109 deletions

View File

@ -3,19 +3,19 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import nodeExternals from "webpack-node-externals";
import { platform } from "os";
import path from "path";
import type { WebpackPluginInstance } from "webpack";
import { DefinePlugin, optimize } from "webpack";
import { main, renderer } from "./library";
import main from "./main";
import renderer from "./renderer";
import { buildDir } from "./vars";
import CircularDependencyPlugin from "circular-dependency-plugin";
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
const config = [
{
...main,
...main(),
entry: {
main: path.resolve(__dirname, "..", "src", "main", "library.ts"),
},
@ -33,7 +33,6 @@ const config = [
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
}),
new ForkTsCheckerPlugin(),
new CircularDependencyPlugin({
cwd: __dirname,
exclude: /node_modules/,
@ -42,7 +41,7 @@ const config = [
],
},
{
...renderer,
...renderer({ showVars: false }),
entry: {
common: path.resolve(__dirname, "..", "src", "common", "library.ts"),
},
@ -55,9 +54,6 @@ const config = [
optimization: {
minimize: false,
},
externals: [
nodeExternals(),
],
plugins: [
new ForkTsCheckerPlugin(),
new CircularDependencyPlugin({
@ -68,7 +64,7 @@ const config = [
],
},
{
...renderer,
...renderer({ showVars: false }),
name: "lens-app-common",
entry: {
renderer: path.resolve(__dirname, "..", "src", "renderer", "library.ts"),
@ -82,9 +78,6 @@ const config = [
optimization: {
minimize: false,
},
externals: [
nodeExternals(),
],
plugins: [
new DefinePlugin({
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,

View File

@ -1,87 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import path from "path";
import type webpack from "webpack";
import nodeExternals from "webpack-node-externals";
import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
import getTypeScriptLoader from "./get-typescript-loader";
import rendererConfig, { iconsAndImagesWebpackRules } from "./renderer";
import { assetsFolderName, buildDir, htmlTemplate, isDevelopment, mainDir, publicPath } from "./vars";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
const defaultRendererConfig = rendererConfig({ showVars: false });
const renderer: webpack.Configuration = ({
...defaultRendererConfig,
plugins: [
// see also: https://github.com/Microsoft/monaco-editor-webpack-plugin#options
new MonacoWebpackPlugin({
// publicPath: "/",
// filename: "[name].worker.js",
languages: ["json", "yaml"],
globalAPI: isDevelopment,
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: htmlTemplate,
inject: true,
hash: true,
templateParameters: {
assetPath: `${publicPath}${assetsFolderName}`,
},
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
});
const main: webpack.Configuration = ({
name: "lens-app-main",
context: __dirname,
target: "electron-main",
mode: isDevelopment ? "development" : "production",
devtool: isDevelopment ? "cheap-module-source-map" : "source-map",
cache: isDevelopment ? { type: "filesystem" } : false,
entry: {
main: path.resolve(mainDir, "index.ts"),
},
output: {
libraryTarget: "global",
path: buildDir,
},
optimization: {
minimize: false,
},
resolve: {
extensions: [".json", ".js", ".ts"],
},
externals: [
nodeExternals(),
],
module: {
parser: {
javascript: {
commonjsMagicComments: true,
},
},
rules: [
{
test: /\.node$/,
use: "node-loader",
},
getTypeScriptLoader({}, /\.ts$/),
...iconsAndImagesWebpackRules(),
],
},
plugins: [],
});
export {
main,
renderer,
};

View File

@ -15,14 +15,14 @@ import { DefinePlugin } from "webpack";
import { buildDir, isDevelopment, mainDir } from "./vars";
import { platform } from "process";
const configs: { (): webpack.Configuration }[] = [];
configs.push((): webpack.Configuration => {
console.info("WEBPACK:main", {
isDevelopment,
mainDir,
buildDir,
});
const main = ({ showVars = true } = {}): webpack.Configuration => {
if (showVars) {
console.info("WEBPACK:main", {
isDevelopment,
mainDir,
buildDir,
});
}
return {
name: "lens-app-main",
@ -72,6 +72,6 @@ configs.push((): webpack.Configuration => {
}) as unknown as WebpackPluginInstance,
],
};
});
};
export default configs;
export default main;