From 8a563a04c2bd614a6190a44afa1b19e45bfd4f7b Mon Sep 17 00:00:00 2001 From: Ian P Bradley Date: Sun, 26 Mar 2023 18:06:48 -0700 Subject: [PATCH] Compile main extension with webpack and add .vscodeignore This cuts the .vsix extension filesize down by over half and markedly increases performance on my setup --- .vscodeignore | 10 +++++ client/src/extension.ts | 2 +- package.json | 8 ++-- server/package.json | 2 +- webpack.config.js | 99 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 .vscodeignore diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..debeb44 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,10 @@ +**/* +!images/camel_icon.png +!syntaxes +!LICENSE +!client/dist/* +!server/dist/* +!server/src/perl +!perlimports.toml +!server/perl.tmLanguage.json +!server/node_modules/vscode-oniguruma/release/onig.wasm \ No newline at end of file diff --git a/client/src/extension.ts b/client/src/extension.ts index 8a41b8a..7c01078 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -18,7 +18,7 @@ let client: LanguageClient; export function activate(context: ExtensionContext) { // The server is implemented in node const serverModule = context.asAbsolutePath( - path.join('server', 'out', 'server.js') + path.join('server', 'dist', 'serverMain.js') ); // The debug options for the server // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging diff --git a/package.json b/package.json index 13e5761..26f2502 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "activationEvents": [ "onLanguage:perl" ], - "main": "./client/out/extension", + "main": "./client/dist/clientMain", "browser": "./client/dist/browserClientMain", "contributes": { "configuration": { @@ -341,7 +341,7 @@ ] }, "scripts": { - "vscode:prepublish": "npm run compile", + "vscode:prepublish": "npm run package", "compile": "tsc -b", "watch": "tsc -b -w", "web-compile": "export NODE_OPTIONS=--openssl-legacy-provider; webpack", @@ -376,9 +376,9 @@ "ts-loader": "^9.3.0", "path-browserify": "^1.0.1" }, - "bin": "server/out/server.js", + "bin": "server/dist/serverMain.js", "pkg": { - "scripts": "server/out/server.js", + "scripts": "server/dist/serverMain.js", "assets": "server/src/**/*", "targets": [ "node16-linux-x64", diff --git a/server/package.json b/server/package.json index 31b41d9..be74b32 100644 --- a/server/package.json +++ b/server/package.json @@ -21,7 +21,7 @@ "vscode-oniguruma": "^2.0.1" }, "scripts": {}, - "main": "./src/out/server.js", + "main": "./src/dist/serverMain.js", "bin": { "perlnavigator": "./bin/perlnavigator" }, diff --git a/webpack.config.js b/webpack.config.js index c288e3b..bf8f9db 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,103 @@ const path = require('path'); +/** @type WebpackConfig */ +const clientConfig = { + context: path.join(__dirname, 'client'), + target: 'node', // web extensions run in a webworker context + entry: { + clientMain: './src/extension.ts', + }, + output: { + filename: '[name].js', + path: path.join(__dirname, 'client', 'dist'), + libraryTarget: 'commonjs', + }, + resolve: { + mainFields: ['module', 'main'], + extensions: ['.ts', '.js'], // support ts-files and js-files + alias: {}, + fallback: { + // path: require.resolve('path-browserify'), + path: false, + process: false, + os: false, + fs: false, + child_process: false, + util: false + }, + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: 'ts-loader', + }, + ], + }, + ], + }, + externals: { + vscode: 'commonjs vscode', // ignored because it doesn't exist + }, + performance: { + hints: false, + }, + devtool: 'source-map', +}; + +/** @type WebpackConfig */ +const serverConfig = { + context: path.join(__dirname, 'server'), + target: 'node', // web extensions run in a webworker context + entry: { + serverMain: './src/server.ts', + }, + output: { + filename: '[name].js', + path: path.join(__dirname, 'server', 'dist'), + libraryTarget: 'var', + library: 'serverExportVar', + }, + resolve: { + mainFields: ['module', 'main'], + extensions: ['.ts', '.js'], // support ts-files and js-files + alias: {}, + fallback: { + //path: require.resolve("path-browserify") + path: false, + process: false, + os: false, + fs: false, + child_process: false, + util: false + }, + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: 'ts-loader', + }, + ], + }, + ], + }, + externals: { + vscode: 'commonjs vscode', // ignored because it doesn't exist + }, + performance: { + hints: false, + }, + devtool: 'source-map', +}; + /** @type WebpackConfig */ const browserClientConfig = { context: path.join(__dirname, 'client'), @@ -100,4 +197,4 @@ const browserServerConfig = { devtool: 'source-map', }; -module.exports = [browserClientConfig, browserServerConfig]; \ No newline at end of file +module.exports = [browserClientConfig, browserServerConfig, clientConfig, serverConfig]; \ No newline at end of file