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

3
.gitignore vendored
View File

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

View File

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

2
.vscode/launch.json vendored
View File

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

17
.vscode/tasks.json vendored
View File

@ -13,7 +13,22 @@
{
"type": "npm",
"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,
"presentation": {
"reveal": "never"

View File

@ -1,6 +1,6 @@
.vscode/**
.vscode-test/**
out/test/**
out/**
test/**
src/**
**/*.map
@ -10,4 +10,11 @@ gulpfile.js
images/**
testprojects/**
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 cp = require('child_process');
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",
"onCommand:JavaDebug.SpecifyProgramArgs"
],
"main": "./out/src/extension",
"main": "./dist/extension",
"contributes": {
"javaExtensions": [
"./server/com.microsoft.java.debug.plugin-0.16.0.jar"
@ -406,8 +406,10 @@
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"watch": "tsc -watch -p ./",
"vscode:prepublish": "npm run build",
"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",
"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",
"mocha": "^5.2.0",
"shelljs": "^0.8.2",
"ts-loader": "^5.3.3",
"tslint": "^5.7.0",
"typescript": "^3.0.1",
"vscode": "^1.1.21"
"vscode": "^1.1.21",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"lodash": "^4.17.10",
"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.
// Licensed under the MIT license.
import * as fs from "fs";
import * as vscode from "vscode";
import TelemetryReporter from "vscode-extension-telemetry";
@ -19,7 +20,7 @@ class Logger implements vscode.Disposable {
return;
}
const extensionPackage = require(context.asAbsolutePath("./package.json"));
const extensionPackage = JSON.parse(fs.readFileSync(context.asAbsolutePath("./package.json"), "utf-8"));
if (extensionPackage) {
const packageInfo = {
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'
}];
};