Skip to content

Commit 4af6c07

Browse files
stephtrconnectdotz
authored andcommitted
Add webpack for extension bundling (#471)
* update extension to use webpack for compilation * update webpack related scripts and settings * update changelog * fix excluding external jest-config * ignore .vsix files
1 parent 21640e2 commit 4af6c07

11 files changed

+1560
-103
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules/
66
out/
77

88
**/.DS_Store
9+
*.vsix

.vscode/launch.json

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
// A launch configuration that compiles the extension and then opens it inside a new window
21
{
3-
"version": "0.1.0",
4-
"configurations": [
5-
{
6-
"type": "node",
7-
"request": "launch",
8-
"name": "Debug Tests",
9-
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
10-
"cwd": "${workspaceRoot}",
11-
"args": [
12-
"--i",
13-
"--config",
14-
"jest.json"
15-
]
16-
},
17-
{
18-
"name": "Launch Extension",
19-
"type": "extensionHost",
20-
"request": "launch",
21-
"runtimeExecutable": "${execPath}",
22-
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
23-
"stopOnEntry": false,
24-
"sourceMaps": true,
25-
"outDir": "${workspaceRoot}/out/src",
26-
"preLaunchTask": "npm"
27-
}
28-
]
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Debug Tests",
8+
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
9+
"cwd": "${workspaceRoot}",
10+
"args": ["--i", "--config", "jest.json"]
11+
},
12+
{
13+
"name": "Launch Extension (development)",
14+
"type": "extensionHost",
15+
"request": "launch",
16+
"runtimeExecutable": "${execPath}",
17+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
18+
"outFiles": ["${workspaceFolder}/out/**/*.js"],
19+
"preLaunchTask": "watch"
20+
},
21+
{
22+
"name": "Launch Extension (production)",
23+
"type": "extensionHost",
24+
"request": "launch",
25+
"runtimeExecutable": "${execPath}",
26+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
27+
"outFiles": ["${workspaceFolder}/out/**/*.js"],
28+
"preLaunchTask": "npm: compile"
29+
}
30+
]
2931
}

.vscode/tasks.json

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
// Available variables which can be used inside of strings.
2-
// ${workspaceRoot}: the root folder of the team
3-
// ${file}: the current opened file
4-
// ${fileBasename}: the current opened file's basename
5-
// ${fileDirname}: the current opened file's dirname
6-
// ${fileExtname}: the current opened file's extension
7-
// ${cwd}: the current working directory of the spawned process
8-
9-
// A task runner that calls a custom npm script that compiles the extension.
101
{
11-
"version": "0.1.0",
12-
13-
// we want to run npm
14-
"command": "npm",
15-
16-
// the command is a shell script
17-
"isShellCommand": true,
18-
19-
// show the output window only if unrecognized errors occur.
20-
"showOutput": "silent",
21-
22-
// we run the custom script "compile" as defined in package.json
23-
"args": ["run", "compile", "--loglevel", "silent"],
24-
25-
// The tsc compiler is started in watching mode
26-
"isWatching": true,
27-
28-
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29-
"problemMatcher": "$tsc-watch"
30-
}
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "watch",
6+
"type": "npm",
7+
"script": "watch",
8+
"isBackground": true,
9+
"problemMatcher": [
10+
{
11+
"owner": "custom",
12+
"pattern": [
13+
{
14+
"regexp": "^PATTERN WON'T MATCH, BUT NEEDED TO BE A VALID PROBLEM MATCHER$",
15+
"file": 1,
16+
"location": 2,
17+
"message": 3
18+
}
19+
],
20+
"background": {
21+
"activeOnStart": true,
22+
"beginsPattern": "^Compilation\\s+starting",
23+
"endsPattern": "^Compilation\\s+finished"
24+
}
25+
}
26+
]
27+
}
28+
]
29+
}

.vscodeignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ src/**
44
**/*.map
55
.gitignore
66
tsconfig.json
7-
vsc-extension-quickstart.md
87
integrations/**
98
**/__mocks__/**
109
**/tests/**
@@ -18,3 +17,7 @@ yarn.lock
1817
yarn-error.log
1918
scripts/
2019
coverage
20+
.github/**
21+
images/**
22+
!images/vscode-jest.png
23+
webpack.config.js

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Bug-fixes within the same version aren't needed
2323

2424
* replaced deprecated vscode.previewHtml command with webview - qalex
2525

26+
* use webpack for compilation, resulting in a much smaller extension size - stephtr
27+
2628
### 2.9.1
2729

2830
* Prevent ANSI escape codes from appearing in test messages - seanpoulter

package.json

+16-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"workspaceContains:node_modules/react-native-scripts",
3030
"onCommand:io.orta.jest.start"
3131
],
32-
"main": "./out/src/extension",
32+
"main": "./out/extension",
3333
"icon": "images/vscode-jest.png",
3434
"contributes": {
3535
"languages": [
@@ -233,11 +233,12 @@
233233
"precommit": "lint-staged",
234234
"ci": "yarn lint && yarn test --coverage",
235235
"clean-out": "rimraf ./out",
236-
"vscode:prepublish": "yarn clean-out && tsc -p ./tsconfig.publish.json",
237-
"compile": "tsc -watch -p ./tsconfig.publish.json",
236+
"vscode:prepublish": "yarn clean-out && yarn compile",
237+
"compile": "webpack --mode production",
238+
"watch": "webpack --mode development --watch --info-verbosity verbose",
238239
"lint": "tslint -c tslint.json 'src/**/*.ts' 'tests/**/*.ts'",
239240
"postinstall": "node ./node_modules/vscode/bin/install",
240-
"test": "tsc && jest",
241+
"test": "jest",
241242
"watch-test": "yarn test -- --watch",
242243
"prettier": "prettier",
243244
"prettier-write": "yarn prettier --parser typescript --no-semi --single-quote --trailing-comma es5 --write --print-width 120",
@@ -248,26 +249,27 @@
248249
"@types/node": "^8.0.31",
249250
"coveralls": "^3.0.0",
250251
"danger": "^2",
252+
"elegant-spinner": "^1.0.1",
251253
"glob": "^7.1.1",
252254
"husky": "^0.14.3",
255+
"istanbul-lib-coverage": "^1.1.1",
256+
"istanbul-lib-source-maps": "^1.1.0",
253257
"jest": "^24.7.0",
258+
"jest-editor-support": "^26.0.0-beta",
259+
"jest-snapshot": "^24.7.0",
254260
"lint-staged": "^4.2.3",
261+
"micromatch": "^2.3.11",
255262
"prettier": "^1.17.0",
256263
"rimraf": "^2.6.2",
257264
"ts-jest": "^24.0.2",
265+
"ts-loader": "^6.0.4",
258266
"tslint": "^5.16.0",
259267
"tslint-config-prettier": "^1.18.0",
260268
"typescript": "^3.4.3",
261-
"typescript-tslint-plugin": "^0.3.1"
262-
},
263-
"dependencies": {
264-
"elegant-spinner": "^1.0.1",
265-
"istanbul-lib-coverage": "^1.1.1",
266-
"istanbul-lib-source-maps": "^1.1.0",
267-
"jest-editor-support": "^26.0.0-beta",
268-
"jest-snapshot": "^24.7.0",
269-
"micromatch": "^2.3.11",
270-
"vscode": "^1.1.33"
269+
"typescript-tslint-plugin": "^0.3.1",
270+
"vscode": "^1.1.33",
271+
"webpack": "^4.35.0",
272+
"webpack-cli": "^3.3.4"
271273
},
272274
"__metadata": {
273275
"id": "7997a8ae-1fae-4022-b834-12f6318aeffd",

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
}
2121
]
2222
},
23-
"exclude": ["integrations", "__mocks__"]
23+
"exclude": ["integrations", "__mocks__", "node_modules"]
2424
}

tsconfig.publish.json

-8
This file was deleted.

tslint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"member-access": false,
1616
"interface-name": false,
1717
"no-empty": [true, "allow-empty-catch", "allow-empty-functions"],
18-
"no-this-assignment": [true, { "allow-destructuring": true }]
18+
"no-this-assignment": [true, { "allow-destructuring": true }],
19+
"no-implicit-dependencies": [true, "dev"]
1920
}
2021
}

webpack.config.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//@ts-check
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
7+
/**@returns {import('webpack').Configuration}*/
8+
module.exports = (env, argv) => {
9+
const isProduction = argv.mode === 'production';
10+
const isDevelopment = !isProduction;
11+
12+
/**@type {any} */
13+
const externals = [
14+
{'jest-config': 'root {}'}, // the jest-config module isn't utilized in this plugin, compiling it would result in unnecessary overhead and errors
15+
{ 'vscode': 'commonjs vscode' } // the vscode-module is created on-the-fly and must be excluded.
16+
];
17+
18+
// during development keep the largest external dependencies out of the bundle in order to speed up build time
19+
if (isDevelopment) {
20+
externals.push('typescript', /^\@babel\/.*/, 'babylon');
21+
}
22+
return {
23+
context: __dirname,
24+
target: 'node',
25+
entry: './src/extension.ts',
26+
output: {
27+
path: path.resolve(__dirname, 'out'),
28+
filename: 'extension.js',
29+
libraryTarget: 'commonjs2',
30+
devtoolModuleFilenameTemplate: '../[resource-path]'
31+
},
32+
devtool: 'source-map',
33+
externals,
34+
resolve: {
35+
extensions: ['.ts', '.js']
36+
},
37+
module: {
38+
rules: [
39+
{
40+
test: /\.ts$/,
41+
exclude: /node_modules/,
42+
use: [
43+
{ loader: 'ts-loader' }
44+
]
45+
}
46+
]
47+
}
48+
};
49+
};

0 commit comments

Comments
 (0)