Skip to content

Commit 8d4d0bb

Browse files
authored
Use webpack to reduce package size (#80)
1 parent 8a3e340 commit 8d4d0bb

File tree

8 files changed

+76
-50
lines changed

8 files changed

+76
-50
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ typings/
6060
out/
6161

6262
.DS_Store
63+
64+
.vscode-test

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outFiles": [
1717
"${workspaceFolder}/out/**/*.js"
1818
],
19-
"preLaunchTask": "watch"
19+
"preLaunchTask": "npm: watch"
2020
},
2121
{
2222
"name": "Extension Tests",

.vscode/tasks.json

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,32 @@
33
{
44
"version": "2.0.0",
55
"tasks": [
6-
{
7-
"label": "watch",
8-
"group": "build",
9-
"isBackground": true,
10-
"presentation": {
11-
"reveal": "never",
12-
},
13-
"problemMatcher": [],
14-
"dependsOn": ["npm: watch", "npm: watch-assets"]
15-
},
166
{
177
"type": "npm",
188
"script": "watch",
19-
"problemMatcher": "$tsc-watch",
20-
"isBackground": true,
21-
"presentation": {
22-
"reveal": "never"
23-
},
24-
"group": {
25-
"kind": "build",
26-
"isDefault": true
27-
}
28-
},
29-
{
30-
"type": "npm",
31-
"script": "watch-assets",
32-
"isBackground": true,
33-
"presentation": {
34-
"reveal": "never",
35-
},
36-
"group": "build",
379
"problemMatcher": {
38-
"pattern": [
10+
"owner": "typescript",
11+
"pattern":[
3912
{
40-
"regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
13+
"regexp": "\\[tsl\\] ERROR",
4114
"file": 1,
4215
"location": 2,
4316
"message": 3
4417
}
4518
],
4619
"background": {
47-
"beginsPattern": "^Webpack is watching the files.*",
4820
"activeOnStart": true,
49-
"endsPattern": "^Built at.*"
21+
"beginsPattern": "Compilation \\w+ starting…",
22+
"endsPattern": "Compilation\\s+finished"
5023
}
24+
},
25+
"isBackground": true,
26+
"presentation": {
27+
"reveal": "never"
28+
},
29+
"group": {
30+
"kind": "build",
31+
"isDefault": true
5132
}
5233
}
5334
]

.vscodeignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
release-notes/**/*.gif
22
release-notes/**/*.png
33
release-notes/**/*.jpg
4-
4+
node_modules
5+
src
6+
.vscode
7+
.github
8+
.gitignore
9+
package-lock.json
10+
tsconfig.json
11+
tslint.json
12+
webpack.config.ext.js
13+
webpack.config.js
14+
out/**/*.map
15+
out/assets/**/*.js

package-lock.json

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

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@
5151
]
5252
},
5353
"scripts": {
54-
"vscode:prepublish": "npm run compile&npm run build-assets",
55-
"compile": "tsc -p ./",
56-
"watch": "tsc -watch -p ./",
57-
"build-assets": "webpack --config webpack.config.js",
58-
"watch-assets": "webpack --config webpack.config.js --watch",
54+
"vscode:prepublish": "npm run build",
55+
"compile": "webpack --config webpack.config.js",
56+
"watch": "webpack --config webpack.config.js --watch --info-verbosity verbose",
57+
"build": "webpack --config webpack.config.js --mode=\"production\"",
5958
"postinstall": "node ./node_modules/vscode/bin/install",
6059
"test": "npm run compile && node ./node_modules/vscode/bin/test"
6160
},

src/overview/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function overviewCmdHandler(context: vscode.ExtensionContext, opera
4646
context.globalState.update(KEY_OVERVIEW_LAST_SHOW_TIME, Date.now().toString());
4747

4848
overviewView.iconPath = vscode.Uri.file(path.join(context.extensionPath, 'logo.lowres.png'));
49-
let buffer = await readFile(require.resolve('./assets/index.html'));
49+
let buffer = await readFile(path.join(context.extensionPath, './out/assets/overview/index.html'));
5050
overviewView.webview.html = buffer.toString();
5151

5252
overviewView.onDidDispose(() => {

webpack.config.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const path = require('path');
55
module.exports = function (env, argv) {
66
env = env || {};
77

8-
return {
8+
return [{
9+
name: 'assets',
10+
mode: 'none',
911
entry: {
1012
overview: './src/overview/assets/index.ts'
1113
},
@@ -31,19 +33,50 @@ module.exports = function (env, argv) {
3133
}]
3234
}]
3335
},
34-
mode: 'development',
3536
output: {
36-
filename: '[name]/assets/index.js',
37+
filename: 'assets/[name]/index.js',
3738
path: path.resolve(__dirname, 'out'),
38-
publicPath: '/'
39+
publicPath: '/',
40+
devtoolModuleFilenameTemplate: "../[resource-path]"
3941
},
4042
plugins: [
4143
new HtmlWebpackPlugin({
42-
filename: path.resolve(__dirname, 'out/overview/assets/index.html'),
44+
filename: path.resolve(__dirname, 'out/assets/overview/index.html'),
4345
template: 'src/overview/assets/index.html',
4446
inlineSource: '.(js|css)$'
4547
}),
4648
new HtmlWebpackInlineSourcePlugin(),
47-
]
48-
}
49+
],
50+
devtool: 'source-map'
51+
}, {
52+
name: 'extension',
53+
target: 'node',
54+
mode: 'none',
55+
entry: {
56+
extension: './src/extension.ts'
57+
},
58+
module: {
59+
rules: [{
60+
test: /\.ts$/,
61+
exclude: /node_modules/,
62+
use: 'ts-loader'
63+
}]
64+
},
65+
resolve: {
66+
modules: ['node_modules', path.resolve(__dirname, 'src')],
67+
mainFiles: ['index'],
68+
extensions: ['.js', '.ts', '.json']
69+
},
70+
output: {
71+
filename: '[name].js',
72+
path: path.resolve(__dirname, 'out'),
73+
libraryTarget: "commonjs2",
74+
publicPath: '/',
75+
devtoolModuleFilenameTemplate: "../[resource-path]"
76+
},
77+
externals: {
78+
vscode: 'commonjs vscode'
79+
},
80+
devtool: 'source-map'
81+
}]
4982
};

0 commit comments

Comments
 (0)