Skip to content

Commit

Permalink
Fix webviews
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed May 24, 2023
1 parent 2ba7416 commit a105ab3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class WebpackGenerator extends AbstractGenerator {
const path = require('path');
const webpack = require('webpack');
const yargs = require('yargs');
const resolvePackagePath = require('resolve-package-path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
Expand All @@ -79,10 +80,17 @@ const development = mode === 'development';
const plugins = [
new CopyWebpackPlugin({
patterns: [{
// copy secondary window html file to lib folder
from: path.resolve(__dirname, 'src-gen/frontend/secondary-window.html')
}]
patterns: [
{
// copy secondary window html file to lib folder
from: path.resolve(__dirname, 'src-gen/frontend/secondary-window.html')
}${this.ifPackage('@theia/plugin-ext', `,
{
// copy webview files to lib folder
from: path.join(resolvePackagePath('@theia/plugin-ext', __dirname), '..', 'src', 'main', 'browser', 'webview', 'pre'),
to: path.resolve(__dirname, 'lib', 'webview', 'pre')
}`)}
]
}),
new webpack.ProvidePlugin({
// the Buffer class doesn't exist in the browser but some dependencies rely on it
Expand Down
8 changes: 6 additions & 2 deletions packages/plugin-ext/src/main/node/plugin-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import * as url from 'url';
const vhost = require('vhost');
import * as express from '@theia/core/shared/express';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
import { injectable, postConstruct } from '@theia/core/shared/inversify';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { WebviewExternalEndpoint } from '../common/webview-protocol';
import { environment } from '@theia/core/shared/@theia/application-package/lib/environment';
import { WsRequestValidatorContribution } from '@theia/core/lib/node/ws-request-validators';
import { MaybePromise } from '@theia/core/lib/common';
import { ApplicationPackage } from '@theia/core/shared/@theia/application-package';

@injectable()
export class PluginApiContribution implements BackendApplicationContribution, WsRequestValidatorContribution {
Expand All @@ -33,6 +34,9 @@ export class PluginApiContribution implements BackendApplicationContribution, Ws

protected serveSameOrigin: boolean = false;

@inject(ApplicationPackage)
protected readonly applicationPackage: ApplicationPackage;

@postConstruct()
protected postConstruct(): void {
const webviewExternalEndpoint = this.webviewExternalEndpoint();
Expand All @@ -42,7 +46,7 @@ export class PluginApiContribution implements BackendApplicationContribution, Ws

configure(app: express.Application): void {
const webviewApp = express();
webviewApp.use('/webview', express.static(path.join(__dirname, '../../../src/main/browser/webview/pre')));
webviewApp.use('/webview', express.static(path.join(this.applicationPackage.projectPath, 'lib', 'webview', 'pre')));
app.use(vhost(this.webviewExternalEndpointRegExp, webviewApp));
}

Expand Down

0 comments on commit a105ab3

Please sign in to comment.