From 98f4f4ba7474c0898909fa9dc17bdd26252d372a Mon Sep 17 00:00:00 2001 From: Dovi Cowan Date: Fri, 7 Oct 2022 17:10:20 +0100 Subject: [PATCH] webpack v5 --- .vscode/launch.json | 3 ++- .vscode/tasks.json | 11 +++++++++-- tsconfig.json | 5 ++++- webpack.config.js | 20 +++++++++++++++++--- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3bb6aee..bd86e5a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,13 +9,14 @@ "name": "Run Extension", "type": "extensionHost", "request": "launch", + "sourceMaps": true, "args": [ "--extensionDevelopmentPath=${workspaceFolder}" ], "outFiles": [ "${workspaceFolder}/dist/**/*.js" ], - "preLaunchTask": "${defaultBuildTask}" + "preLaunchTask": "${defaultBuildTask}", }, { "name": "Extension Tests", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 136cbbc..a1a07d0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,8 +7,8 @@ "type": "npm", "script": "watch", "problemMatcher": [ - "$ts-webpack-watch", - "$tslint-webpack-watch" + "$ts-webpack-watch", + "$tslint-webpack-watch" ], "isBackground": true, "presentation": { @@ -28,6 +28,13 @@ "reveal": "never" }, "group": "build" + }, + { + "type": "npm", + "script": "pretest", + "problemMatcher": [], + "label": "npm: pretest", + "detail": "npm run test-compile && npm run lint" } ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 2b21eef..274861d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,10 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ - "experimentalDecorators": true + "experimentalDecorators": true, + "types": [ + "node" + ] }, "exclude": [ "node_modules", diff --git a/webpack.config.js b/webpack.config.js index 538f0ac..d45e174 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,10 +2,16 @@ 'use strict'; +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); + const path = require('path'); +const webpack = require('webpack'); /**@type {import('webpack').Configuration}*/ const config = { + node: { + __dirname: true + }, target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') @@ -14,16 +20,24 @@ const config = { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ path: path.resolve(__dirname, 'dist'), filename: 'extension.js', - libraryTarget: 'commonjs2' + libraryTarget: 'commonjs2', + devtoolModuleFilenameTemplate: '../[resource-path]' }, - devtool: 'nosources-source-map', + devtool: 'eval-source-map', externals: { vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ }, resolve: { + // mainFields: ['browser', 'module', 'main'], // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader - extensions: ['.ts', '.js'] + extensions: ['.ts', '.js'], + fallback: { + "fs": false + } }, + plugins: [ + new NodePolyfillPlugin() + ], module: { rules: [ {