Skip to content

Upgrade packages and scripts #7

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 15 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/ext-src"
}
]
}
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/ext-src"],
"preLaunchTask": "buildExtension"
}
]
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "buildExtension",
"type": "npm",
"script": "compile",
"problemMatcher": []
}
]
}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,8 +27,4 @@ Things we did on top of Create React App TypeScript template
* Onlu resources whose scheme is `vscode-resource` can be accessed.
* For all resources we are going to use in the webview, we change their schemes to `vscode-resource`
* Since we only allow local resources, absolute path for styles/images (e.g., `/static/media/logo.svg`) will not work. We add a `.env` file which sets `PUBLIC_URL` to `./` and after bundling, resource urls will be relative.
* We add baseUrl `<base href="${vscode.Uri.file(path.join(this._extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">` and then all relative paths work.

## Limitations

Right now you can only run production bits (`yarn run build`) in the webview, how to make dev bits work (webpack dev server) is still unknown yet. Suggestions and PRs welcome !
* We add baseUrl `<base href="${vscode.Uri.file(path.join(this._extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">` and then all relative paths work.
7 changes: 3 additions & 4 deletions ext-src/extension.ts
Original file line number Diff line number Diff line change
@@ -88,9 +88,8 @@ class ReactPanel {

private _getHtmlForWebview() {
const manifest = require(path.join(this._extensionPath, 'build', 'asset-manifest.json'));
const mainScript = manifest['main.js'];
const mainStyle = manifest['main.css'];

const mainScript = manifest.files['main.js'];
const mainStyle = manifest.files['main.css'];
const scriptPathOnDisk = vscode.Uri.file(path.join(this._extensionPath, 'build', mainScript));
const scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });
const stylePathOnDisk = vscode.Uri.file(path.join(this._extensionPath, 'build', mainStyle));
@@ -108,7 +107,7 @@ class ReactPanel {
<title>React App</title>
<link rel="stylesheet" type="text/css" href="${styleUri}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}';style-src vscode-resource: 'unsafe-inline' http: https: data:;">
<base href="${vscode.Uri.file(path.join(this._extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">
<base href="${this._panel.webview.asWebviewUri(vscode.Uri.file(path.join(this._extensionPath, 'build')))}/">
</head>

<body>
32 changes: 15 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "vscode-webview-react",
"version": "0.1.0",
"engines": {
"vscode": "^1.23.0"
"vscode": "^1.45.1"
},
"publisher": "rebornix",
"activationEvents": [
@@ -19,30 +19,28 @@
]
},
"dependencies": {
"react": "^16.3.2",
"react-dom": "^16.3.2",
"terser": "3.16.0",
"vscode": "^1.1.17"
},
"resolutions": {
"terser": "3.14.1"
"@types/vscode": "^1.45.1",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"scripts": {
"vscode:prepublish": "./scripts/build-non-split.js && tsc -p tsconfig.extension.json",
"postinstall": "node ./node_modules/vscode/bin/install",
"vscode:prepublish": "npm run compile",
"start": "react-scripts start",
"build": "./scripts/build-non-split.js && tsc -p tsconfig.extension.json",
"build": "npm run compile",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"compile": "./scripts/build-non-split.js && tsc -p tsconfig.extension.json",
"pretest": "npm run compile"
},
"devDependencies": {
"@types/jest": "^23.3.13",
"@types/node": "^10.1.2",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.11",
"@types/react": "^16.3.14",
"@types/react-dom": "^16.0.5",
"react-scripts": "^2.1.3",
"rewire": "^4.0.1",
"typescript": "^3.3.1"
"react-scripts": "^3.4.1",
"rewire": "^5.0.0",
"typescript": "^3.3.1",
"terser": "^4.7.0"
},
"browserslist": [
">0.2%",
32 changes: 12 additions & 20 deletions tsconfig.extension.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "build",
"lib": [
"es6",
"dom"
],
"sourceMap": true,
"rootDir": ".",
"strict": true
},
"include": [
"ext-src"
],
"exclude": [
"node_modules",
".vscode-test"
]
}
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "build",
"lib": ["es6", "dom"],
"sourceMap": true,
"rootDir": ".",
"strict": true
},
"include": ["ext-src"],
"exclude": ["node_modules", ".vscode-test"]
}
10 changes: 2 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
@@ -19,7 +15,5 @@
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
"include": ["src"]
}
Loading