Skip to content

Commit 471e877

Browse files
committed
Fix build
Signed-off-by: paulober <[email protected]>
1 parent c81cc2b commit 471e877

File tree

5 files changed

+82
-76
lines changed

5 files changed

+82
-76
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"--extensionDevelopmentPath=${workspaceFolder}"
1414
],
1515
"outFiles": [
16-
"${workspaceFolder}/dist/**/*.js"
16+
"${workspaceFolder}/dist/extension.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}"
1919
},

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"type": "npm",
88
"script": "watch",
9-
"problemMatcher": "$tsc-watch",
9+
"problemMatcher": "$ts-webpack-watch",
1010
"isBackground": true,
1111
"presentation": {
1212
"reveal": "never",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"workspaceContains:.micropico",
5555
"onFileSystem:pico"
5656
],
57-
"main": "./dist/extension",
57+
"main": "./dist/extension.js",
5858
"os": [
5959
"win32",
6060
"darwin",
@@ -648,8 +648,8 @@
648648
"vscode:prepublish": "npm run package",
649649
"postinstall": "patch-package && node ./scripts/postinstall.mjs",
650650
"cp-prebuilds": "node -e \"const fs=require('fs');fs.rmSync('prebuilds',{recursive:true,force:true});fs.cpSync('node_modules/@serialport/bindings-cpp/prebuilds','prebuilds',{recursive:true});\"",
651-
"compile": "tsc --build tsconfig.json",
652-
"watch": "npm run cp-prebuilds && tsc --build tsconfig.json --watch",
651+
"compile": "tsc --build tsconfig.json --noEmit false",
652+
"watch": "npm run cp-prebuilds && webpack --watch --mode development",
653653
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
654654
"package-local": "npm run clean && webpack --mode production && npm run cp-prebuilds",
655655
"package": "npm run clean && webpack --mode production",

tsconfig.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
"lib": [
66
"ES2022"
77
],
8-
"sourceMap": false,
9-
"inlineSourceMap": true,
8+
"sourceMap": true,
9+
"inlineSourceMap": false,
10+
"noEmit": true,
1011
"removeComments": true,
1112
"noUnusedLocals": true,
1213
"strictNullChecks": true,
1314
"strictPropertyInitialization": true,
1415
"rootDir": "src",
15-
"outDir": "dist",
16+
"outDir": "out",
1617
"strict": true,
1718
"noImplicitAny": true,
1819
"noImplicitReturns": true,
1920
"forceConsistentCasingInFileNames": true,
20-
"moduleResolution": "node16"
21+
"moduleResolution": "node16",
22+
"esModuleInterop": true
2123
}
2224
}

webpack.config.js

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,80 @@
22

33
'use strict';
44

5-
const path = require('path');
5+
const path = require('node:path');
66

7-
/**@type {import('webpack').Configuration}*/
8-
const config = {
9-
target: 'node',
10-
entry: './src/extension.mts',
11-
output: {
12-
path: path.resolve(__dirname, "dist"),
13-
filename: 'extension.js',
14-
libraryTarget: 'commonjs2',
15-
devtoolModuleFilenameTemplate: '../[resource-path]',
16-
},
17-
node: {
18-
__dirname: false,
19-
},
20-
devtool: 'source-map',
21-
externals: {
22-
vscode: "commonjs vscode"
23-
},
24-
resolve: {
25-
extensions: ['.mts', '.ts', '.mjs', '.js'],
26-
mainFields: ['main', 'module'],
27-
extensionAlias: {
28-
'.mjs': ['.mts', '.mjs'], // allow imports written as ./file.mjs to resolve ./file.mts
29-
'.js': ['.ts', '.js'], // allow imports written as ./file.js to resolve ./file.ts
7+
//@ts-ignore
8+
module.exports = (_env, argv) => {
9+
const isProd = argv.mode === 'production';
10+
11+
/** @type {import('webpack').Configuration} */
12+
const config = {
13+
name: 'extension',
14+
target: 'node',
15+
entry: './src/extension.mts',
16+
mode: isProd ? 'production' : 'development',
17+
output: {
18+
path: path.resolve(__dirname, "dist"),
19+
filename: 'extension.js',
20+
libraryTarget: 'commonjs2',
21+
},
22+
node: {
23+
__dirname: false,
24+
},
25+
devtool: 'source-map',
26+
externals: {
27+
vscode: "commonjs vscode"
3028
},
31-
},
32-
module: {
33-
rules: [{
34-
test: /\.[cm]?ts$/,
35-
exclude: /node_modules/,
36-
use: [{
37-
// configure TypeScript loader:
38-
// * enable sources maps for end-to-end source maps
39-
loader: 'ts-loader',
40-
options: {
41-
compilerOptions: {
42-
"inlineSourceMap": true,
29+
resolve: {
30+
extensions: ['.mts', '.ts', '.mjs', '.js'],
31+
mainFields: ['main', 'module'],
32+
extensionAlias: {
33+
'.mjs': ['.mts', '.mjs'], // allow imports written as ./file.mjs to resolve ./file.mts
34+
'.js': ['.ts', '.js'], // allow imports written as ./file.js to resolve ./file.ts
35+
},
36+
},
37+
module: {
38+
rules: [{
39+
test: /\.[cm]?ts$/,
40+
exclude: /node_modules/,
41+
use: [{
42+
// configure TypeScript loader:
43+
// * enable sources maps for end-to-end source maps
44+
loader: 'ts-loader',
45+
options: {
46+
transpileOnly: true
4347
}
44-
}
48+
}]
49+
}, {
50+
test: /.node$/,
51+
loader: 'node-loader',
4552
}]
46-
}, {
47-
test: /.node$/,
48-
loader: 'node-loader',
49-
}]
50-
},
51-
optimization: {
52-
minimize: true
53-
},
54-
stats: {
55-
warnings: false
56-
}
57-
};
53+
},
54+
optimization: {
55+
minimize: isProd
56+
},
57+
stats: {
58+
warnings: false
59+
}
60+
};
5861

59-
const uninstallerEsm = {
60-
name: 'uninstaller',
61-
target: 'node',
62-
mode: 'production',
63-
entry: './vscodeUninstall.mjs', // your existing file with TLA
64-
experiments: { outputModule: true, topLevelAwait: true },
65-
output: {
66-
path: path.resolve(__dirname, 'dist'),
67-
filename: 'vscodeUninstall.mjs',
68-
library: { type: 'module' },
69-
chunkFormat: 'module',
70-
clean: false,
71-
},
72-
devtool: false,
73-
resolve: { extensions: ['.mjs', '.js'] },
74-
};
62+
/** @type {import('webpack').Configuration} */
63+
const uninstallerEsm = {
64+
name: 'uninstaller',
65+
target: 'node',
66+
mode: 'production',
67+
entry: './vscodeUninstall.mjs', // your existing file with TLA
68+
experiments: { outputModule: true, topLevelAwait: true },
69+
output: {
70+
path: path.resolve(__dirname, 'dist'),
71+
filename: 'vscodeUninstall.mjs',
72+
library: { type: 'module' },
73+
chunkFormat: 'module',
74+
clean: false,
75+
},
76+
devtool: false,
77+
resolve: { extensions: ['.mjs', '.js'] },
78+
};
7579

76-
// @ts-ignore
77-
module.exports = [config, uninstallerEsm];
80+
return [config, uninstallerEsm];
81+
};

0 commit comments

Comments
 (0)