Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webpack bundling for faster startup #717

Merged
merged 3 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": "npm"
},
{
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"activationEvents": [
"*"
],
"main": "./out/src/extension",
"main": "./out/extension.js",
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -143,26 +143,30 @@
}
},
"scripts": {
"vscode:prepublish": "npm run tslint-check && npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"vscode:prepublish": "npm run tslint-check && webpack --mode production",
"compile": "webpack",
"watch": "webpack --mode development --watch",
"postinstall": "node ./node_modules/vscode/bin/install",
"tslint-check": "tslint -c ./tslint.json ./src/**/*.ts ./src/*.ts",
"format": "prettier --write './src/**/*.ts'",
"test": "npm run vscode:prepublish && node ./node_modules/bin/mocha --recursive"
"test": "npm run tslint-check && tsc -p ./ && mocha --recursive \"./out/test/**/*.js\""
},
"devDependencies": {
"@types/fs-extra": "^5.0.4",
"@types/node": "^10.12.10",
"@types/chai": "4.1.7",
"@types/fs-extra": "^5.0.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.10",
"chai": "^4.2.0",
"clean-webpack-plugin": "^1.0.0",
"mocha": "^5.2.0",
"prettier": "^1.15.2",
"ts-loader": "^5.3.0",
"tslint": "^5.11.0",
"tslint-plugin-prettier": "^2.0.0",
"typescript": "^3.1.2",
"vscode": "^1.1.21"
"vscode": "^1.1.21",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
},
"dependencies": {
"@octokit/rest": "^16.0.1",
Expand Down
8 changes: 5 additions & 3 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,11 @@ export default class Commons {
outputChannel.appendLine(`--------------------`);

outputChannel.appendLine(`Files ${upload ? "Upload" : "Download"}ed:`);
files.filter(item => item.fileName.indexOf(".") > 0).forEach(item => {
outputChannel.appendLine(` ${item.fileName} > ${item.gistName}`);
});
files
.filter(item => item.fileName.indexOf(".") > 0)
.forEach(item => {
outputChannel.appendLine(` ${item.fileName} > ${item.gistName}`);
});

outputChannel.appendLine(``);
outputChannel.appendLine(`Extensions Ignored:`);
Expand Down
6 changes: 4 additions & 2 deletions src/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ export class Localize {
// then merger the Language pack
// just in case the resolveLanguage bundle missing the translation and fallback with default language
if (resolvedLanguage !== defaultResvoleLanguage) {
defaultLanguageBundle = require(path.join(file + defaultResvoleLanguage));
defaultLanguageBundle = JSON.parse(
fs.readFileSync(path.join(file + defaultResvoleLanguage), "utf-8")
);
}

const languageFilePath = path.join(file + resolvedLanguage);

const isExistResolvedLanguage = await fs.pathExists(languageFilePath);

const ResolvedLanguageBundle = isExistResolvedLanguage
? require(languageFilePath)
? JSON.parse(fs.readFileSync(languageFilePath, "utf-8"))
: {};

// merger with default language bundle
Expand Down
44 changes: 44 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackOptions **/

"use strict";

const path = require("path");
const CleanWebpackPlugin = require("clean-webpack-plugin");

/** @type WebpackOptions */
const config = {
mode: "none",
target: "node",
entry: "./src/extension.ts",
output: {
filename: "extension.js",
path: path.resolve(__dirname, "out"),
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "file:///[absolute-resource-path]"
},
resolve: {
extensions: [".ts", ".js"],
alias: {
deepmerge$: path.resolve(__dirname, "node_modules/deepmerge/dist/umd.js")
}
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: "ts-loader"
}
]
},
externals: {
vscode: "commonjs vscode",
fsevents: "commonjs fsevents",
"original-fs": "commonjs original-fs"
},
devtool: "source-map",
plugins: [new CleanWebpackPlugin(["out"])]
};

module.exports = config;