Use webpack to reduce package size (#533)

* Use webpack to reduce package size

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* Fix build failure

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* Add license header

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
This commit is contained in:
Jinbo Wang 2019-02-15 13:15:26 +08:00 committed by GitHub
parent 4a85531207
commit a5d2bdfd3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2640 additions and 31 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ node_modules
.vscode-test/ .vscode-test/
vscode-java-debug-*.vsix vscode-java-debug-*.vsix
packages/ packages/
dist

View File

@ -23,4 +23,5 @@ install:
script: script:
- gulp tslint - gulp tslint
- vsce package - vsce package
- npm run compile
- npm test --silent - npm test --silent

2
.vscode/launch.json vendored
View File

@ -22,7 +22,7 @@
"stopOnEntry": false, "stopOnEntry": false,
"sourceMaps": true, "sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ], "outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm: watch" "preLaunchTask": "npm: compile"
} }
] ]
} }

17
.vscode/tasks.json vendored
View File

@ -13,7 +13,22 @@
{ {
"type": "npm", "type": "npm",
"script": "watch", "script": "watch",
"problemMatcher": "$tsc-watch", "problemMatcher": {
"owner": "typescript",
"pattern": [
{
"regexp": "\\[tsl\\] ERROR",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "Compilation \\w+ starting…",
"endsPattern": "Compilation\\s+finished"
}
},
"isBackground": true, "isBackground": true,
"presentation": { "presentation": {
"reveal": "never" "reveal": "never"

View File

@ -1,6 +1,6 @@
.vscode/** .vscode/**
.vscode-test/** .vscode-test/**
out/test/** out/**
test/** test/**
src/** src/**
**/*.map **/*.map
@ -11,3 +11,10 @@ images/**
testprojects/** testprojects/**
TestPlan.md TestPlan.md
.github/** .github/**
.travis.yml
tsconfig.json
tslint.json
packages
package-lock.json
node_modules
webpack.config.js

View File

@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
const gulp = require("gulp"); const gulp = require("gulp");
const cp = require('child_process'); const cp = require('child_process');
const tslint = require("gulp-tslint"); const tslint = require("gulp-tslint");

2577
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@
"onDebugResolve:java", "onDebugResolve:java",
"onCommand:JavaDebug.SpecifyProgramArgs" "onCommand:JavaDebug.SpecifyProgramArgs"
], ],
"main": "./out/src/extension", "main": "./dist/extension",
"contributes": { "contributes": {
"javaExtensions": [ "javaExtensions": [
"./server/com.microsoft.java.debug.plugin-0.16.0.jar" "./server/com.microsoft.java.debug.plugin-0.16.0.jar"
@ -406,8 +406,10 @@
} }
}, },
"scripts": { "scripts": {
"vscode:prepublish": "tsc -p ./", "vscode:prepublish": "npm run build",
"watch": "tsc -watch -p ./", "compile": "tsc -p . && webpack --config webpack.config.js",
"watch": "webpack --config webpack.config.js --watch --info-verbosity verbose",
"build": "webpack --config webpack.config.js --mode=\"production\"",
"postinstall": "node ./node_modules/vscode/bin/install", "postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./scripts/download-vscode-for-system-tests && node ./scripts/install-vsix-dependencies redhat.java && node ./scripts/install-vsix-dependencies vscode-java-debug-0.16.0.vsix && node ./scripts/run-vscode-tests" "test": "node ./scripts/download-vscode-for-system-tests && node ./scripts/install-vsix-dependencies redhat.java && node ./scripts/install-vsix-dependencies vscode-java-debug-0.16.0.vsix && node ./scripts/run-vscode-tests"
}, },
@ -423,13 +425,16 @@
"gulp-tslint": "^8.1.2", "gulp-tslint": "^8.1.2",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"shelljs": "^0.8.2", "shelljs": "^0.8.2",
"ts-loader": "^5.3.3",
"tslint": "^5.7.0", "tslint": "^5.7.0",
"typescript": "^3.0.1", "typescript": "^3.0.1",
"vscode": "^1.1.21" "vscode": "^1.1.21",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
}, },
"dependencies": { "dependencies": {
"lodash": "^4.17.10", "lodash": "^4.17.10",
"vscode-extension-telemetry": "0.1.0", "vscode-extension-telemetry": "0.1.0",
"vscode-extension-telemetry-wrapper": "0.3.5" "vscode-extension-telemetry-wrapper": "0.3.8"
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. // Licensed under the MIT license.
import * as fs from "fs";
import * as vscode from "vscode"; import * as vscode from "vscode";
import TelemetryReporter from "vscode-extension-telemetry"; import TelemetryReporter from "vscode-extension-telemetry";
@ -19,7 +20,7 @@ class Logger implements vscode.Disposable {
return; return;
} }
const extensionPackage = require(context.asAbsolutePath("./package.json")); const extensionPackage = JSON.parse(fs.readFileSync(context.asAbsolutePath("./package.json"), "utf-8"));
if (extensionPackage) { if (extensionPackage) {
const packageInfo = { const packageInfo = {
name: extensionPackage.name, name: extensionPackage.name,

39
webpack.config.js Normal file
View File

@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
const path = require('path');
module.exports = function (env, argv) {
env = env || {};
return [{
name: 'extension',
target: 'node',
mode: 'none',
entry: {
extension: './src/extension.ts'
},
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
use: 'ts-loader'
}]
},
resolve: {
modules: ['node_modules', path.resolve(__dirname, 'src')],
mainFiles: ['index'],
extensions: ['.js', '.ts', '.json']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: "commonjs2",
publicPath: '/',
devtoolModuleFilenameTemplate: "../[resource-path]"
},
externals: {
vscode: 'commonjs vscode'
},
devtool: 'source-map'
}];
};