Skip to content

Commit

Permalink
Fix/loading speed (webpack) (KreativJos#51)
Browse files Browse the repository at this point in the history
* [Add] Extension packaging via webpack
* [Fix] Removed a lot of files from the package (.vscodeignore)
  • Loading branch information
KreativJos authored Oct 19, 2021
1 parent 54d32dc commit 5e0cc52
Show file tree
Hide file tree
Showing 7 changed files with 785 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/out/src/**/*.js"
"${workspaceRoot}/dist/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
"preLaunchTask": "buildDev"
},
{
"name": "Launch Tests",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
"**/node_modules": true,
"out": true,
"vsix/": true
},
"typescript.tsc.autoDetect": "off",
// "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
Expand Down
53 changes: 40 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
{
"version": "2.0.0",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"label": "build",
"command": "yarn",
"type": "shell",
"args": [
"run",
"compile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
},
{
"label": "buildDev",
"command": "yarn",
"type": "shell",
"args": [
"run",
"compileDev"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"command": "echo",
"group": {
"kind": "test",
"isDefault": true
},
"args": [
"Run tests in VS Code by launching the debugger with the 'Launch Tests' configuration."
]
},
]
}
6 changes: 5 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.vscode/**
.vscode-test/**
out/test/**
out/**
test/**
src/**
**/*.map
Expand All @@ -12,3 +12,7 @@ vsc-extension-quickstart.md
**/.eslintrc.json
**/*.map
**/*.ts
featureimages/**
ovsx.key
node_modules/**
publish.sh
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"onCommand:csharpextensions.createUwpUserControl",
"onCommand:csharpextensions.createUwpResourceFile"
],
"main": "./out/src/extension",
"main": "./dist/extension",
"contributes": {
"submenus": [
{
Expand Down Expand Up @@ -166,12 +166,11 @@
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"vscode:prepublish": "tsc -p ./ && webpack --mode production",
"compile": "tsc -p ./ && yarn run lint",
"compileDev": "tsc -p ./ && yarn run lint && webpack --mode development",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
"lint": "eslint src --ext ts"
},
"devDependencies": {
"@types/glob": "^7.1.3",
Expand All @@ -185,12 +184,15 @@
"eslint": "^7.19.0",
"glob": "^7.1.6",
"mocha": "^8.2.1",
"ts-loader": "^9.2.6",
"typescript": "^4.1.3",
"vscode-test": "^1.5.0"
"vscode-test": "^1.5.0",
"webpack": "^5.58.2",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"find-up-glob": "^1.0.0",
"lodash": "^4.7.0",
"xml2js": "^0.4.23"
}
}
}
40 changes: 40 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

//@ts-check

const path = require('path');
/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/
entry: './src/extension.ts', // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]",
},
devtool: 'source-map',
externals: {
vscode: "commonjs vscode" // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/
},
resolve: { // support reading TypeScript and JavaScript files, πŸ“– -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
node: {
__dirname: false //preserve the default node.js behavior for __dirname
},
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
}]
}]
},
}

module.exports = config;
Loading

0 comments on commit 5e0cc52

Please sign in to comment.