This bundles the extension files using esbuild, as recommended by VSCode. This reduces the size of the extension from 34MB to less than 5MB. Gulp will still run TypeScript to check types, but will not use the TypeScript compiler output in the bundle. Tests are now run separately, outside of Gulp, so their data doesn't need to be copied anymore. See: https://code.visualstudio.com/api/working-with-extensions/bundling-extension
58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import webpack from "webpack";
|
|
import { config } from "./webpack.config";
|
|
|
|
export function compileView(cb: (err?: Error) => void) {
|
|
doWebpack(config, true, cb);
|
|
}
|
|
|
|
export function watchView(cb: (err?: Error) => void) {
|
|
const watchConfig = {
|
|
...config,
|
|
watch: true,
|
|
watchOptions: {
|
|
aggregateTimeout: 200,
|
|
poll: 1000,
|
|
},
|
|
};
|
|
doWebpack(watchConfig, false, cb);
|
|
}
|
|
|
|
function doWebpack(
|
|
internalConfig: webpack.Configuration,
|
|
failOnError: boolean,
|
|
cb: (err?: Error) => void,
|
|
) {
|
|
const resultCb = (error: Error | undefined, stats?: webpack.Stats) => {
|
|
if (error) {
|
|
cb(error);
|
|
}
|
|
if (stats) {
|
|
console.log(
|
|
stats.toString({
|
|
errorDetails: true,
|
|
colors: true,
|
|
assets: false,
|
|
builtAt: false,
|
|
version: false,
|
|
hash: false,
|
|
entrypoints: false,
|
|
timings: false,
|
|
modules: false,
|
|
errors: true,
|
|
}),
|
|
);
|
|
if (stats.hasErrors()) {
|
|
if (failOnError) {
|
|
cb(new Error("Compilation errors detected."));
|
|
return;
|
|
} else {
|
|
console.error("Compilation errors detected.");
|
|
}
|
|
}
|
|
cb();
|
|
}
|
|
};
|
|
|
|
webpack(internalConfig, resultCb);
|
|
}
|