Skip to content

Commit c263c4a

Browse files
committed
build: revise webpack build with example from vscode lsp
remove root shared webpack config, settings stored in project level for now.
1 parent 3e9a730 commit c263c4a

File tree

11 files changed

+320
-139
lines changed

11 files changed

+320
-139
lines changed

packages/client/package-lock.json

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "client",
3+
"displayName": "Code Action UI Sample - Client",
4+
"version": "1.0.0",
5+
"private": true,
6+
"author": "Microsoft Corporation",
7+
"license": "MIT",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/Microsoft/vscode-extension-samples.git"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/Microsoft/vscode-extension-samples/issues"
14+
},
15+
"engines": {
16+
"vscode": "^1.52.0"
17+
},
18+
"devDependencies": {
19+
"@types/vscode": "1.52.0"
20+
},
21+
"dependencies": {
22+
"vscode-languageclient": "^7.0.0"
23+
}
24+
}

packages/client/project.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@
88
"build": {
99
"executor": "@nrwl/webpack:webpack",
1010
"outputs": ["{options.outputPath}"],
11-
"defaultConfiguration": "development",
11+
"defaultConfiguration": "production",
1212
"options": {
1313
"outputPath": "dist/packages/client",
1414
"compiler": "babel",
15-
"main": "packages/client/src/main.ts",
15+
"main": "packages/client/src/extension.ts",
1616
"tsConfig": "packages/client/tsconfig.app.json",
17-
"webpackConfig": "packages/client/webpack.config.js"
17+
"webpackConfig": "packages/client/webpack.config.js",
18+
"target": "node",
19+
"outputFileName": "extension.js"
1820
},
1921
"configurations": {
20-
"development": {},
21-
"production": {
22-
"optimization": true,
23-
"outputHashing": "media",
24-
"namedChunks": false,
25-
"extractLicenses": true,
26-
"vendorChunk": false
27-
}
22+
"production": {}
2823
}
2924
},
3025
"serve": {

packages/client/src/extension.ts

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,65 @@
66

77
import * as path from 'path';
88
import { ExtensionContext, window as Window } from 'vscode';
9-
import { LanguageClient, LanguageClientOptions, RevealOutputChannelOn, ServerOptions, TransportKind } from 'vscode-languageclient/node';
9+
import {
10+
LanguageClient,
11+
LanguageClientOptions,
12+
RevealOutputChannelOn,
13+
ServerOptions,
14+
TransportKind,
15+
} from 'vscode-languageclient/node';
1016

1117
export function activate(context: ExtensionContext): void {
12-
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'sampleServer.js'));
13-
let serverOptions: ServerOptions = {
14-
run: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } },
15-
debug: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } }
16-
};
18+
const serverModule = context.asAbsolutePath(
19+
path.join('dist', 'packages', 'server', 'server.js')
20+
);
21+
const serverOptions: ServerOptions = {
22+
run: {
23+
module: serverModule,
24+
transport: TransportKind.ipc,
25+
options: { cwd: process.cwd() },
26+
},
27+
debug: {
28+
module: serverModule,
29+
transport: TransportKind.ipc,
30+
options: { cwd: process.cwd() },
31+
},
32+
};
1733

18-
let clientOptions: LanguageClientOptions = {
19-
documentSelector: [{ scheme: 'file', language: 'plaintext' }],
20-
diagnosticCollectionName: 'sample',
21-
revealOutputChannelOn: RevealOutputChannelOn.Never,
22-
progressOnInitialization: true,
23-
middleware: {
24-
executeCommand: async (command, args, next) => {
25-
const selected = await Window.showQuickPick(['Visual Studio', 'Visual Studio Code']);
26-
if (selected === undefined) {
27-
return next(command, args);
28-
}
29-
args = args.slice(0);
30-
args.push(selected);
31-
return next(command, args);
32-
}
33-
}
34-
};
34+
const clientOptions: LanguageClientOptions = {
35+
documentSelector: [{ scheme: 'file', language: 'plaintext' }],
36+
diagnosticCollectionName: 'sample',
37+
revealOutputChannelOn: RevealOutputChannelOn.Never,
38+
progressOnInitialization: true,
39+
middleware: {
40+
executeCommand: async (command, args, next) => {
41+
const selected = await Window.showQuickPick([
42+
'Visual Studio',
43+
'Visual Studio Code',
44+
]);
45+
if (selected === undefined) {
46+
return next(command, args);
47+
}
48+
args = args.slice(0);
49+
args.push(selected);
50+
return next(command, args);
51+
},
52+
},
53+
};
3554

36-
let client: LanguageClient;
37-
try {
38-
client = new LanguageClient('UI Sample', serverOptions, clientOptions);
39-
} catch (err) {
40-
Window.showErrorMessage(`The extension couldn't be started. See the output channel for details.`);
41-
return;
42-
}
43-
client.registerProposedFeatures();
55+
let client: LanguageClient;
56+
try {
57+
client = new LanguageClient('UI Sample', serverOptions, clientOptions);
58+
} catch (err) {
59+
Window.showErrorMessage(
60+
`The extension couldn't be started. See the output channel for details.`
61+
);
62+
return;
63+
}
64+
client.registerProposedFeatures();
4465

45-
context.subscriptions.push(
46-
client.start(),
47-
);
66+
context.subscriptions.push(client.start());
4867
}
4968

50-
export function deactivate() {
51-
}
69+
// eslint-disable-next-line @typescript-eslint/no-empty-function
70+
export function deactivate() {}

packages/client/tsconfig.spec.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"module": "commonjs",
66
"types": ["jest", "node"]
77
},
8-
"files": ["src/test-setup.ts"],
98
"include": [
109
"jest.config.ts",
1110
"src/**/*.test.ts",

packages/client/webpack.config.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
11
const { composePlugins, withNx, withWeb } = require('@nrwl/webpack');
22

3-
const withDefaults = require('../../shared.webpack.config');
43
const path = require('path');
54

65
// Nx plugins for webpack.
76
module.exports = composePlugins(withNx(), withWeb(), (config) => {
87
// Update the webpack config as needed here.
98
// e.g. `config.plugins.push(new MyPlugin())`
10-
const /**@type WebpackConfig*/ merged = withDefaults(
11-
/**@type WebpackConfig*/ config
12-
);
139

14-
merged.context = path.join(__dirname);
15-
merged.entry = {
16-
extension: './src/extension.ts',
10+
config.mode = 'none'; // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
11+
config.target = 'node'; // extensions run in a node context
12+
config.node = {
13+
__dirname: false, // leave the __dirname-behaviour intact
14+
};
15+
16+
config.resolve = {
17+
mainFields: ['module', 'main'],
18+
extensions: ['.ts', '.js'], // support ts-files and js-files
19+
};
20+
21+
config.module = {
22+
rules: [
23+
{
24+
test: /\.ts$/,
25+
exclude: /node_modules/,
26+
use: [
27+
{
28+
// configure TypeScript loader:
29+
// * enable sources maps for end-to-end source maps
30+
loader: 'ts-loader',
31+
options: {
32+
compilerOptions: {
33+
sourceMap: true,
34+
},
35+
},
36+
},
37+
],
38+
},
39+
],
1740
};
18-
merged.output = {
19-
filename: 'extension.js',
20-
path: path.join(__dirname, 'out'),
41+
config.externals = {
42+
vscode: 'commonjs vscode', // ignored because it doesn't exist
43+
};
44+
45+
config.output.libraryTarget = 'commonjs';
46+
47+
// yes, really source maps
48+
config.devtool = 'source-map';
49+
50+
config.context = path.join(__dirname);
51+
config.entry = {
52+
extension: './src/extension.ts',
2153
};
2254

23-
return merged;
55+
return config;
2456
});

packages/server/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "server",
3+
"version": "1.0.0",
4+
"private": true,
5+
"author": "Microsoft Corporation",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/Microsoft/vscode-extension-samples.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/Microsoft/vscode-extension-samples/issues"
13+
},
14+
"engines": {
15+
"node": "*"
16+
},
17+
"dependencies": {
18+
"vscode-uri": "^3.0.2",
19+
"vscode-languageserver": "^7.0.0",
20+
"vscode-languageserver-textdocument": "^1.0.1"
21+
}
22+
}

0 commit comments

Comments
 (0)