Use Webpack in production mode for releases

This will set the `mode` of Webpack to `production` for release builds.
It will also stop inlining the sourcemap and instead produce a separate
file which is excluded by `.vscodeignore`.

In terms of the bundled extension, this will add 1 file
(`out/webview.js.LICENSE.txt`). It decreases the size of the VSIX file
from 4.28MB to 1.77MB.
This commit is contained in:
Koen Vlaswinkel
2023-01-13 14:23:51 +02:00
parent f82fde35ee
commit f6f8b68ce9
3 changed files with 6 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import {
writeFile,
} from "fs-extra";
import { resolve, join } from "path";
import { isDevBuild } from "./dev";
export interface DeployedPackage {
distPath: string;
@@ -53,8 +54,6 @@ export async function deployPackage(
await readFile(packageJsonPath, "utf8"),
);
// Default to development build; use flag --release to indicate release build.
const isDevBuild = !process.argv.includes("--release");
const distDir = join(__dirname, "../../../dist");
await mkdirs(distDir);

View File

@@ -0,0 +1,2 @@
// Default to development build; use flag --release to indicate release build.
export const isDevBuild = !process.argv.includes("--release");

View File

@@ -1,9 +1,10 @@
import { resolve } from "path";
import * as webpack from "webpack";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { isDevBuild } from "./dev";
export const config: webpack.Configuration = {
mode: "development",
mode: isDevBuild ? "development" : "production",
entry: {
webview: "./src/view/webview.tsx",
},
@@ -11,7 +12,7 @@ export const config: webpack.Configuration = {
path: resolve(__dirname, "..", "out"),
filename: "[name].js",
},
devtool: "inline-source-map",
devtool: isDevBuild ? "inline-source-map" : "source-map",
resolve: {
extensions: [".js", ".ts", ".tsx", ".json"],
fallback: {