From 5576af0ba454abeb93c0028ef0d0831b7d071972 Mon Sep 17 00:00:00 2001
From: "Hung-Han (Henry) Chen" <1474479+chenhunghan@users.noreply.github.com>
Date: Tue, 24 Nov 2020 17:54:25 +0800
Subject: [PATCH] Use webpack instead of tsc to output extension-api.ts
Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>
---
package.json | 2 +-
tsconfig.extensions.json | 8 ++--
webpack.extensions.ts | 93 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 6 deletions(-)
create mode 100644 webpack.extensions.ts
diff --git a/package.json b/package.json
index eeda6f6c4c..5b1535adb4 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,7 @@
"compile:main": "yarn run webpack --config webpack.main.ts",
"compile:renderer": "yarn run webpack --config webpack.renderer.ts",
"compile:i18n": "yarn run lingui compile",
- "compile:extension-types": "yarn run tsc -p ./tsconfig.extensions.json --outDir src/extensions/npm/extensions/dist",
+ "compile:extension-types": "yarn run webpack --config webpack.extensions.ts",
"npm:fix-package-version": "yarn run ts-node build/set_npm_version.ts",
"build:linux": "yarn run compile && electron-builder --linux --dir -c.productName=Lens",
"build:mac": "yarn run compile && electron-builder --mac --dir -c.productName=Lens",
diff --git a/tsconfig.extensions.json b/tsconfig.extensions.json
index 21579bae38..4b6b142f64 100644
--- a/tsconfig.extensions.json
+++ b/tsconfig.extensions.json
@@ -1,11 +1,9 @@
{
"extends": "./tsconfig.json",
- "files": [
- "src/extensions/extension-api.ts",
- ],
"compilerOptions": {
"module": "CommonJS",
- "sourceMap": false,
- "declaration": true
+ "declaration": true, // should output .d.ts
+ "sourceMap": true, // for use with webpack's devtool: 'inline-source-map'
+ "outDir": "./src/extensions/npm/extensions/dist" // where .d.ts output
}
}
diff --git a/webpack.extensions.ts b/webpack.extensions.ts
new file mode 100644
index 0000000000..bde47c8598
--- /dev/null
+++ b/webpack.extensions.ts
@@ -0,0 +1,93 @@
+
+import path from 'path';
+import webpack from "webpack";
+import nodeExternals from "webpack-node-externals";
+import MiniCssExtractPlugin from "mini-css-extract-plugin";
+
+import { sassCommonVars } from "./src/common/vars";
+
+export default function (): webpack.Configuration {
+ return {
+ // Compile for Electron for renderer process
+ // see
+ target: "electron-renderer",
+ externals: [
+ // in order to ignore all modules in node_modules folder
+ //
+ nodeExternals()
+ ],
+ devtool: 'inline-source-map',
+ entry: './src/extensions/extension-api.ts',
+ output: {
+ filename: 'extension-api.js',
+ // need to be an absolute path
+ path: path.resolve(__dirname, 'src/extensions/npm/extensions/dist/src/extensions'),
+ libraryTarget: "commonjs"
+ },
+ module: {
+ rules: [
+ {
+ test: /\.tsx?$/,
+ loader: 'ts-loader',
+ options: {
+ configFile: 'tsconfig.extensions.json',
+ }
+ },
+ // for src/renderer/components/fonts/roboto-mono-nerd.ttf
+ // in src/renderer/components/dock/terminal.ts 95:25-65
+ {
+ test: /\.(ttf|eot|woff2?)$/,
+ use: {
+ loader: "url-loader",
+ options: {
+ name: "fonts/[name].[ext]"
+ }
+ }
+ },
+ // for import scss files
+ {
+ test: /\.s?css$/,
+ use: [
+ // https://webpack.js.org/plugins/mini-css-extract-plugin/
+ MiniCssExtractPlugin.loader,
+ {
+ loader: "css-loader",
+ options: {
+ sourceMap: true
+ },
+ },
+ {
+ loader: "sass-loader",
+ options: {
+ sourceMap: true,
+ prependData: `@import "${path.basename(sassCommonVars)}";`,
+ sassOptions: {
+ includePaths: [
+ path.dirname(sassCommonVars)
+ ]
+ },
+ }
+ },
+ ]
+ }
+ ]
+ },
+ resolve: {
+ extensions: ['.ts', '.tsx']
+ },
+ 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',
+ // }),
+ new MiniCssExtractPlugin({
+ filename: "[name].css",
+ }),
+ ]
+ };
+}