mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow to import app as a library (#6722)
* unify build fs layout Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use currentApp path for static files Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to import open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to customize both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix compile-library script Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove bundled extensions Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * similar interface for both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use startApp on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * Fix injection cycle (somehow) Signed-off-by: Sebastian Malton <sebastian@malton.name> * use cwd in download_binaries Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce applicationInformationToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * register applicationInformationInjectable in main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to define bundled extensions via appStart Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * compile node-fetch automatically via prepare Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * define peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * rename application-information-token.injectable.ts -> application-information-token.ts Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * monaco-editor as externals Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor application-information Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce bundledExtensionInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * mark library exports as experimental Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move extension npm package files & add release automation Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add missing build files to package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix bad merge conflict resolve Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix package.json name Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to set mode via startApp Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * revert unnecessary changes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack: fix extensionOutDir Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove unnecessary peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce nodeEnvInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove NODE_ENV from environmentVariablesInjectable Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix jest modulePathIgnorePatterns Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix duplicate injectable registration Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build executableName Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ba908c860d
commit
97551bb7f0
57 files changed
+712
-263
No files matched your search
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
||||
import { platform } from "os";
|
||||
import path from "path";
|
||||
import type { WebpackPluginInstance } from "webpack";
|
||||
import { DefinePlugin, optimize } from "webpack";
|
||||
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 rendererConfig = renderer({ showVars: false });
|
||||
|
||||
const config = [
|
||||
{
|
||||
...main(),
|
||||
entry: {
|
||||
main: path.resolve(__dirname, "..", "src", "main", "library.ts"),
|
||||
},
|
||||
output: {
|
||||
library: {
|
||||
type: "commonjs2",
|
||||
},
|
||||
path: path.resolve(buildDir, "library"),
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
}),
|
||||
new CircularDependencyPlugin({
|
||||
cwd: __dirname,
|
||||
exclude: /node_modules/,
|
||||
failOnError: true,
|
||||
}) as unknown as WebpackPluginInstance,
|
||||
],
|
||||
},
|
||||
{
|
||||
...rendererConfig,
|
||||
name: "lens-app-common",
|
||||
entry: {
|
||||
common: path.resolve(__dirname, "..", "src", "common", "library.ts"),
|
||||
},
|
||||
output: {
|
||||
library: {
|
||||
type: "commonjs2",
|
||||
},
|
||||
path: path.resolve(buildDir, "library"),
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
plugins: [
|
||||
new ForkTsCheckerPlugin(),
|
||||
new CircularDependencyPlugin({
|
||||
cwd: __dirname,
|
||||
exclude: /node_modules/,
|
||||
failOnError: true,
|
||||
}) as unknown as WebpackPluginInstance,
|
||||
],
|
||||
},
|
||||
{
|
||||
...rendererConfig,
|
||||
entry: {
|
||||
renderer: path.resolve(__dirname, "..", "src", "renderer", "library.ts"),
|
||||
},
|
||||
output: {
|
||||
library: {
|
||||
type: "commonjs2",
|
||||
},
|
||||
path: path.resolve(buildDir, "library"),
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
externals: {
|
||||
...(rendererConfig.externals as any),
|
||||
"monaco-editor": "commonjs monaco-editor",
|
||||
},
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: "[name].css",
|
||||
runtime: false,
|
||||
}),
|
||||
new optimize.LimitChunkCountPlugin({
|
||||
maxChunks: 1,
|
||||
}),
|
||||
new ForkTsCheckerPlugin(),
|
||||
new CircularDependencyPlugin({
|
||||
cwd: __dirname,
|
||||
exclude: /node_modules/,
|
||||
failOnError: true,
|
||||
}) as unknown as WebpackPluginInstance,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default config;
|
||||
+15
-10
@@ -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",
|
||||
@@ -45,6 +45,11 @@ configs.push((): webpack.Configuration => {
|
||||
nodeExternals(),
|
||||
],
|
||||
module: {
|
||||
parser: {
|
||||
javascript: {
|
||||
commonjsMagicComments: true,
|
||||
},
|
||||
},
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
@@ -67,6 +72,6 @@ configs.push((): webpack.Configuration => {
|
||||
}) as unknown as WebpackPluginInstance,
|
||||
],
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export default configs;
|
||||
export default main;
|
||||
+7
-2
@@ -38,7 +38,7 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
||||
devtool: isDevelopment ? "cheap-module-source-map" : "source-map",
|
||||
cache: isDevelopment ? { type: "filesystem" } : false,
|
||||
entry: {
|
||||
[appName]: path.resolve(rendererDir, "bootstrap.tsx"),
|
||||
[appName]: path.resolve(rendererDir, "index.ts"),
|
||||
},
|
||||
output: {
|
||||
libraryTarget: "global",
|
||||
@@ -70,6 +70,11 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
||||
minimize: false,
|
||||
},
|
||||
module: {
|
||||
parser: {
|
||||
javascript: {
|
||||
commonjsMagicComments: true,
|
||||
},
|
||||
},
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
@@ -102,7 +107,7 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
||||
}),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
filename: `${appName}.html`,
|
||||
filename: "index.html",
|
||||
template: htmlTemplate,
|
||||
inject: true,
|
||||
hash: true,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ 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 extensionOutDir = path.join(process.cwd(), "packages", "extensions", "dist");
|
||||
export const assetsFolderName = "assets";
|
||||
export const rendererDir = path.join(process.cwd(), "src", "renderer");
|
||||
export const appName = isDevelopment
|
||||
|
||||
Reference in new issue
Block a user