Skip to content

Commit af9cd09

Browse files
evidolobfbricon
andauthored
Add code bundling with webpack (#596)
* Optimize size with webpack Signed-off-by: Fred Bricon <fbricon@gmail.com> * Add bundling yaml-ls code Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com> * fix test run Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com> * include only needed prettier files Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com> Co-authored-by: Fred Bricon <fbricon@gmail.com>
1 parent e123e82 commit af9cd09

File tree

9 files changed

+809
-23
lines changed

9 files changed

+809
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules/
22
out/
3+
dist/
34
.vscode-test/
45
test/testFixture/.vscode
6+
*.vsix
7+
.DS_Store

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode-test
22
out
33
syntaxes/
4+
dist

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
1111
"stopOnEntry": false,
1212
"sourceMaps": true,
13-
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
13+
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
1414
"preLaunchTask": "compile typescript",
1515
"env": {
1616
"VSCODE_REDHAT_TELEMETRY_DEBUG":"true"
@@ -21,6 +21,7 @@
2121
"type": "extensionHost",
2222
"request": "launch",
2323
"runtimeExecutable": "${execPath}",
24+
"preLaunchTask": "compile test",
2425
"args": [
2526
"--disable-extension=ms-kubernetes-tools.vscode-kubernetes-tools",
2627
"--extensionDevelopmentPath=${workspaceFolder}",

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
"isBackground": true,
1919
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
2020
"problemMatcher": "$tsc-watch"
21+
},
22+
{
23+
"label": "compile test",
24+
// the command is a shell script
25+
"type": "shell",
26+
// we run the custom npm script "compile" as defined in package.json
27+
"command": "yarn test-compile",
28+
// show the output window only if unrecognized errors occur.
29+
"presentation": {
30+
"reveal": "never"
31+
},
32+
// The tsc compiler is started in watching mode
33+
"isBackground": true,
34+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
35+
"problemMatcher": "$tsc-watch"
2136
}
2237
]
2338
}

.vscodeignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.vscode/**
22
typings/**
3-
out/test/**
3+
out/**
44
test/**
55
src/**
66
images/**
7+
node_modules/**
8+
scripts/**
9+
Jenkinsfile
10+
prettier*
711
**/*.map
812
.gitignore
913
.github/**
@@ -14,3 +18,6 @@ CONTRIBUTING.md
1418
.vscode-test/**
1519
**/**.vsix
1620
**/**.tar.gz
21+
!node_modules/prettier/index.js
22+
!node_modules/prettier/third-party.js
23+
!node_modules/prettier/parser-yaml.js

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"autocompletion",
4949
"validation"
5050
],
51-
"main": "./out/src/extension",
51+
"main": "./dist/extension",
5252
"contributes": {
5353
"languages": [
5454
{
@@ -190,12 +190,14 @@
190190
"scripts": {
191191
"build": "yarn run clean && yarn run lint && yarn run vscode:prepublish",
192192
"check-dependencies": "node ./scripts/check-dependencies.js",
193-
"clean": "rimraf out",
194-
"compile": "tsc -watch -p ./",
193+
"clean": "rimraf out && rimraf dist",
194+
"compile": "webpack --mode none",
195195
"format": "prettier --write .",
196196
"lint": "eslint -c .eslintrc.js --ext .ts src test",
197-
"test": "sh scripts/e2e.sh",
198-
"vscode:prepublish": "tsc -p ./"
197+
"test": "yarn test-compile && sh scripts/e2e.sh",
198+
"vscode:prepublish": "webpack --mode production",
199+
"watch": "webpack --mode development --watch --info-verbosity verbose",
200+
"test-compile": "tsc -p ./"
199201
},
200202
"devDependencies": {
201203
"@types/chai": "^4.2.12",
@@ -217,9 +219,13 @@
217219
"rimraf": "^3.0.2",
218220
"sinon": "^9.0.3",
219221
"sinon-chai": "^3.5.0",
222+
"ts-loader": "^9.2.5",
220223
"ts-node": "^3.3.0",
221224
"typescript": "4.1.2",
222-
"vscode-test": "^1.4.0"
225+
"umd-compat-loader": "^2.1.2",
226+
"vscode-test": "^1.4.0",
227+
"webpack": "^5.52.1",
228+
"webpack-cli": "^4.8.0"
223229
},
224230
"dependencies": {
225231
"@redhat-developer/vscode-redhat-telemetry": "0.4.2",

src/extension.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ export async function activate(context: ExtensionContext): Promise<SchemaExtensi
8787
telemetry.sendStartupEvent();
8888

8989
// The YAML language server is implemented in node
90-
const serverModule = context.asAbsolutePath(
91-
path.join('node_modules', 'yaml-language-server', 'out', 'server', 'src', 'server.js')
92-
);
93-
90+
const serverModule = context.asAbsolutePath(path.join('.', 'dist', 'languageserver.js'));
9491
// The debug options for the server
9592
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
9693

webpack.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
//@ts-check
5+
6+
'use strict';
7+
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
const path = require('path');
10+
11+
/**@type {import('webpack').Configuration}*/
12+
const config = {
13+
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
14+
node: {
15+
__dirname: false,
16+
__filename: false,
17+
},
18+
entry: {
19+
extension: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
20+
languageserver: './node_modules/yaml-language-server/out/server/src/server.js',
21+
},
22+
output: {
23+
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
24+
path: path.resolve(__dirname, 'dist'),
25+
filename: '[name].js',
26+
libraryTarget: 'commonjs2',
27+
devtoolModuleFilenameTemplate: '../[resource-path]',
28+
},
29+
devtool: 'source-map',
30+
externals: {
31+
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/
32+
prettier: 'commonjs prettier',
33+
},
34+
resolve: {
35+
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
36+
extensions: ['.ts', '.js'],
37+
},
38+
module: {
39+
rules: [
40+
{
41+
test: /\.ts$/,
42+
exclude: /node_modules/,
43+
use: [
44+
{
45+
loader: 'ts-loader',
46+
},
47+
],
48+
},
49+
{
50+
test: /node_modules[\\|/](vscode-json-languageservice)/,
51+
use: { loader: 'umd-compat-loader' },
52+
},
53+
],
54+
},
55+
};
56+
module.exports = config;

0 commit comments

Comments
 (0)