2021-05-12 18:33:26 +03:00
|
|
|
/**
|
2022-01-18 11:18:10 +03:00
|
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
2021-05-12 18:33:26 +03:00
|
|
|
*/
|
|
|
|
|
2020-11-26 11:12:53 +03:00
|
|
|
|
2020-12-02 12:22:10 +03:00
|
|
|
import path from "path";
|
2021-05-19 19:11:54 +03:00
|
|
|
import type webpack from "webpack";
|
2022-04-13 17:39:35 +03:00
|
|
|
import { cssModulesWebpackRule, fontsLoaderWebpackRules, iconsAndImagesWebpackRules } from "./renderer";
|
|
|
|
import { extensionEntry, extensionOutDir, isDevelopment } from "./vars";
|
2020-11-26 11:12:53 +03:00
|
|
|
|
2021-02-09 18:33:27 +03:00
|
|
|
export default function generateExtensionTypes(): webpack.Configuration {
|
2020-12-02 12:22:10 +03:00
|
|
|
return {
|
|
|
|
// Compile for Electron for renderer process
|
|
|
|
// see <https://webpack.js.org/configuration/target/>
|
|
|
|
target: "electron-renderer",
|
2022-04-13 17:39:35 +03:00
|
|
|
entry: extensionEntry,
|
2020-12-02 12:22:10 +03:00
|
|
|
// this is the default mode, so we should make it explicit to silence the warning
|
2022-02-25 18:20:06 +03:00
|
|
|
mode: isDevelopment ? "development" : "production",
|
2020-12-02 12:22:10 +03:00
|
|
|
output: {
|
|
|
|
filename: "extension-api.js",
|
|
|
|
// need to be an absolute path
|
2022-04-13 17:39:35 +03:00
|
|
|
path: path.resolve(extensionOutDir, "src", "extensions"),
|
2020-12-02 12:22:10 +03:00
|
|
|
// can be use in commonjs environments
|
|
|
|
// e.g. require('@k8slens/extensions')
|
2021-11-03 00:38:20 +03:00
|
|
|
libraryTarget: "commonjs",
|
2020-12-02 12:22:10 +03:00
|
|
|
},
|
2021-02-09 18:33:27 +03:00
|
|
|
cache: isDevelopment,
|
|
|
|
optimization: {
|
|
|
|
minimize: false, // speed up types compilation
|
|
|
|
},
|
2022-02-25 18:20:06 +03:00
|
|
|
ignoreWarnings: [
|
|
|
|
/Critical dependency: the request of a dependency is an expression/, // see who is using request: "npm ls request"
|
|
|
|
/require.extensions is not supported by webpack./, // handlebars
|
|
|
|
],
|
2021-05-15 00:24:22 +03:00
|
|
|
stats: "errors-warnings",
|
2020-12-02 12:22:10 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
2022-01-31 17:49:36 +03:00
|
|
|
{
|
|
|
|
test: /\.node$/,
|
|
|
|
loader: "ignore-loader",
|
|
|
|
},
|
2020-12-02 12:22:10 +03:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loader: "ts-loader",
|
|
|
|
options: {
|
|
|
|
// !! ts-loader will use tsconfig.json at folder root
|
|
|
|
// !! changes in tsconfig.json may have side effects
|
|
|
|
// !! on '@k8slens/extensions' module
|
|
|
|
compilerOptions: {
|
|
|
|
declaration: true, // output .d.ts
|
|
|
|
sourceMap: false, // to override sourceMap: true in tsconfig.json
|
2022-04-13 17:39:35 +03:00
|
|
|
outDir: extensionOutDir, // where the .d.ts should be located
|
2021-11-03 00:38:20 +03:00
|
|
|
},
|
|
|
|
},
|
2020-11-26 11:12:53 +03:00
|
|
|
},
|
2022-02-25 18:20:06 +03:00
|
|
|
cssModulesWebpackRule({ styleLoader: "style-loader" }),
|
|
|
|
...fontsLoaderWebpackRules(),
|
|
|
|
...iconsAndImagesWebpackRules(),
|
2021-11-03 00:38:20 +03:00
|
|
|
],
|
2020-12-02 12:22:10 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
2021-11-03 00:38:20 +03:00
|
|
|
extensions: [".ts", ".tsx", ".js"],
|
2020-12-02 12:22:10 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// In ts-loader's README they said to output a built .d.ts file,
|
|
|
|
// you can set "declaration": true in tsconfig.extensions.json,
|
|
|
|
// and use the DeclarationBundlerPlugin in your webpack config... but
|
|
|
|
// !! the DeclarationBundlerPlugin doesn't work anymore, author archived it.
|
|
|
|
// https://www.npmjs.com/package/declaration-bundler-webpack-plugin
|
|
|
|
// new DeclarationBundlerPlugin({
|
|
|
|
// moduleName: '@k8slens/extensions',
|
|
|
|
// out: 'extension-api.d.ts',
|
|
|
|
// })
|
2021-11-03 00:38:20 +03:00
|
|
|
],
|
2020-12-02 12:22:10 +03:00
|
|
|
};
|
2020-11-26 11:12:53 +03:00
|
|
|
}
|