Skip to content

Commit

Permalink
configure webpack to compile lib
Browse files Browse the repository at this point in the history
  • Loading branch information
thadeu committed Sep 13, 2023
1 parent 3fd95d7 commit 68d153f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.52.0"
"vscode": "^1.82.0"
},
"categories": [
"Programming Languages",
Expand Down Expand Up @@ -131,20 +131,23 @@
],
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"compile": "npx webpack --mode production",
"publish": "npx vsce publish",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/lodash.get": "^4.4.7",
"@types/lodash.isempty": "^4.4.7",
"@types/mocha": "^2.2.42",
"@types/node": "^20.6.0",
"fs": "^0.0.1-security",
"@types/vscode": "^1.82.0",
"ts-loader": "^9.4.4",
"tslint": "^5.20.1",
"typescript": "^2.6.1",
"vscode": "^1.1.37"
"typescript": "5",
"vsce": "^2.15.0",
"vscode": "^1.1.37",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"lodash.get": "^4.4.2",
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from 'vscode'
import { readFile } from 'fs/promises'
import get from 'lodash.get'

type SettingsType = {
Expand Down Expand Up @@ -78,12 +77,14 @@ async function localSettings(): Promise<SettingsType> {
const files = await vscode.workspace.findFiles('**/.vscode/settings.json')
const file = files.find((o) => String(o.path).includes(workspace.uri.path))

const data = JSON.parse(await readFile(file.fsPath, 'utf8'))
const buffer = await vscode.workspace.fs.readFile(vscode.Uri.parse(file.fsPath))
const data = JSON.parse(buffer.toString())

return data
} catch (error) {
console.error(error)
vscode.window.showWarningMessage('RSpec Extension: parse settings.json failed')

vscode.window.showErrorMessage('RSpec Extension: parse settings.json failed')

return null
}
Expand Down
42 changes: 26 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"esModuleInterop": true,
"lib": [
"es6",
"dom"
],
"sourceMap": true,
"rootDir": ".",
},
"exclude": [
"node_modules",
".vscode-test"
]
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"esModuleInterop": true,
"lib": [
"es6",
"dom"
],
"types": [
"node",
"vscode"
],
"strict": false,
"sourceMap": true,
"rootDir": "."
},
"include": [
"src/**/*.ts",
"./node_modules/vscode/vscode.d.ts",
"./node_modules/vscode/lib/*",
],
"exclude": [
"node_modules",
".vscode-test"
]
}
40 changes: 40 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require('path')

/**@type {import('webpack').Configuration}*/
const config = {
target: 'node',
entry: './src/extension.ts',
output: {
path: path.resolve(__dirname, 'out/src'),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode',
},
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
module: 'es6',
},
},
},
],
},
],
},
}

module.exports = config

0 comments on commit 68d153f

Please sign in to comment.